Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/LocalVariable/hashCode/hashcode001.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.hashCode;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* complies with its spec. <BR>39* <BR>40* The cases for testing are as follows. <BR>41* <BR>42* When a gebuggee creates an object containing two <BR>43* methods with equal sets of variables and arguments, <BR>44* a debugger creates following LocalVariable objects: <BR>45* - two for the same variable in the debuggee; <BR>46* - for "the same type - different name" variable in <BR>47* the same method in the debuggee; <BR>48* - for "same name-type - different methods" variable; <BR>49* <BR>50* applies the method LocalVariable.hashCode() and <BR>51* compares pairs of hashCodes to check up that <BR>52* - hashCodes are equal if two LocalVariable mirror <BR>53* the same variable or argument <BR>54* in the same method in the debuggee; <BR>55* - hashCodes are not equal otherwise. <BR>56* <BR>57*/5859public class hashcode001 {6061//----------------------------------------------------- templete section62static final int PASSED = 0;63static final int FAILED = 2;64static final int PASS_BASE = 95;6566//----------------------------------------------------- templete parameters67static final String68sHeader1 = "\n==> nsk/jdi/LocalVariable/hashCode/hashcode001 ",69sHeader2 = "--> hashcode001: ",70sHeader3 = "##> hashcode001: ";7172//----------------------------------------------------- main method7374public static void main (String argv[]) {75int result = run(argv, System.out);76System.exit(result + PASS_BASE);77}7879public static int run (String argv[], PrintStream out) {80return new hashcode001().runThis(argv, out);81}8283//-------------------------------------------------- log procedures8485//private static boolean verbMode = false;8687private static Log logHandler;8889private static void log1(String message) {90logHandler.display(sHeader1 + message);91}92private static void log2(String message) {93logHandler.display(sHeader2 + message);94}95private static void log3(String message) {96logHandler.complain(sHeader3 + message);97}9899// ************************************************ test parameters100101private String debuggeeName =102"nsk.jdi.LocalVariable.hashCode.hashcode001a";103104String mName = "nsk.jdi.LocalVariable.hashCode";105106//====================================================== test program107108static ArgumentHandler argsHandler;109static int testExitCode = PASSED;110111//------------------------------------------------------ common section112113private int runThis (String argv[], PrintStream out) {114115Debugee debuggee;116117argsHandler = new ArgumentHandler(argv);118logHandler = new Log(out, argsHandler);119Binder binder = new Binder(argsHandler, logHandler);120121if (argsHandler.verbose()) {122debuggee = binder.bindToDebugee(debuggeeName + " -vbs"); // *** tp123} else {124debuggee = binder.bindToDebugee(debuggeeName); // *** tp125}126127IOPipe pipe = new IOPipe(debuggee);128129debuggee.redirectStderr(out);130log2("hashcode001a debuggee launched");131debuggee.resume();132133String line = pipe.readln();134if ((line == null) || !line.equals("ready")) {135log3("signal received is not 'ready' but: " + line);136return FAILED;137} else {138log2("'ready' recieved");139}140141VirtualMachine vm = debuggee.VM();142143//------------------------------------------------------ testing section144log1(" TESTING BEGINS");145146for (int i = 0; ; i++) {147pipe.println("newcheck");148line = pipe.readln();149150if (line.equals("checkend")) {151log2(" : returned string is 'checkend'");152break ;153} else if (!line.equals("checkready")) {154log3("ERROR: returned string is not 'checkready'");155testExitCode = FAILED;156break ;157}158159log1("new check: #" + i);160161//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part162163List listOfLoadedClasses = vm.classesByName(mName + ".TestClass");164165if (listOfLoadedClasses.size() != 1) {166testExitCode = FAILED;167log3("ERROR: listOfLoadedClasses.size() != 1 " +168listOfLoadedClasses.size());169break ;170}171172List methods1 =173((ReferenceType) listOfLoadedClasses.get(0)).174methodsByName("testmethod1");175List methods2 =176((ReferenceType) listOfLoadedClasses.get(0)).177methodsByName("testmethod2");178179Method testMethod1 = (Method) methods1.get(0);180Method testMethod2 = (Method) methods2.get(0);181182String names1[] = { "bl1", "bt1", "ch1", "db1",183"fl1", "in1", "ln1", "sh1",184"class2_1", "iface_1", "cfc_1", "param1" };185String names2[] = { "bl2", "bt2", "ch2", "db2",186"fl2", "in2", "ln2", "sh2",187"class2_2", "iface_2", "cfc_2", "param2" };188189int i2;190191for (i2 = 0; i2 < names1.length; i2++) {192193log2("new check: #" + i2);194195List lVars1 = null;196List lVars2 = null;197List lVars3 = null;198List lVars4 = null;199200try {201lVars1 = testMethod1.variablesByName(names1[i2]);202lVars2 = testMethod1.variablesByName(names1[i2]);203lVars3 = testMethod1.variablesByName(names2[i2]);204lVars4 = testMethod2.variablesByName(names1[i2]);205} catch ( AbsentInformationException e ) {206log3("ERROR: AbsentInformationException for " +207"lVars = testMethod_i.variablesByName(names[i2])" );208testExitCode = FAILED;209continue;210}211if (lVars1.size() != 1 || lVars2.size() != 1 ||212lVars3.size() != 1 || lVars4.size() != 1 ) {213testExitCode = FAILED;214log3("ERROR: lVars-i.size() != 1 for i2= " + i2);215continue;216}217218LocalVariable lVar1 = (LocalVariable) lVars1.get(0);219LocalVariable lVar2 = (LocalVariable) lVars2.get(0);220LocalVariable lVar3 = (LocalVariable) lVars3.get(0);221LocalVariable lVar4 = (LocalVariable) lVars4.get(0);222223224if (lVar1.hashCode() != lVar2.hashCode()) {225testExitCode = FAILED;226log3("ERROR: lVar1.hashCode() != lVar2.hashCode() for check# " + i2);227}228if (lVar1.hashCode() == lVar3.hashCode()) {229testExitCode = FAILED;230log3("ERROR: lVar1.hashCode() == lVar3.hashCode()) for check# " + i2);231}232if (lVar1.hashCode() == lVar4.hashCode()) {233testExitCode = FAILED;234log3("ERROR: lVar1.hashCode() == lVar4.hashCode() for check# " + i2);235}236}237//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~238}239log1(" TESTING ENDS");240241//-------------------------------------------------- test summary section242//------------------------------------------------- standard end section243244pipe.println("quit");245log2("waiting for the debuggee to finish ...");246debuggee.waitFor();247248int status = debuggee.getStatus();249if (status != PASSED + PASS_BASE) {250log3("debuggee returned UNEXPECTED exit status: " +251status + " != PASS_BASE");252testExitCode = FAILED;253} else {254log2("debuggee returned expected exit status: " +255status + " == PASS_BASE");256}257258if (testExitCode != PASSED) {259logHandler.complain("TEST FAILED");260}261return testExitCode;262}263}264265266