Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/IntegerValue/hashCode/hashcode001.java
41161 views
/*1* Copyright (c) 2000, 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.IntegerValue.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* IntegerValue. <BR>36* <BR>37* The test checks up that results of the method <BR>38* <code>com.sun.jdi.IntegerValue.hashCode()</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 executes the following : <BR>44* public static integer plus1_1 = +1; <BR>45* public static integer plus1_2 = +1; <BR>46* <BR>47* which a debugger mirros as : <BR>48* <BR>49* IntegerValue ivplus1_1; <BR>50* IntegerValue ivplus1_2; <BR>51* <BR>52* the following is true: <BR>53* <BR>54* ivplus1_1.hashCode() == ivplus1_1.hashCode() <BR>55* ivplus1_1.hashCode() == ivplus1_2.hashCode() <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/IntegerValue/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 procedures8485private 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.IntegerValue.hashCode.hashcode001a";103104//====================================================== test program105106static ArgumentHandler argsHandler;107static int testExitCode = PASSED;108109//------------------------------------------------------ common section110111private int runThis (String argv[], PrintStream out) {112113Debugee debuggee;114115argsHandler = new ArgumentHandler(argv);116logHandler = new Log(out, argsHandler);117Binder binder = new Binder(argsHandler, logHandler);118119if (argsHandler.verbose()) {120debuggee = binder.bindToDebugee(debuggeeName + " -vbs"); // *** tp121} else {122debuggee = binder.bindToDebugee(debuggeeName); // *** tp123}124125IOPipe pipe = new IOPipe(debuggee);126127debuggee.redirectStderr(out);128log2("hashcode001a debuggee launched");129debuggee.resume();130131String line = pipe.readln();132if ((line == null) || !line.equals("ready")) {133log3("signal received is not 'ready' but: " + line);134return FAILED;135} else {136log2("'ready' recieved");137}138139VirtualMachine vm = debuggee.VM();140141//------------------------------------------------------ testing section142log1(" TESTING BEGINS");143144for (int i = 0; ; i++) {145pipe.println("newcheck");146line = pipe.readln();147148if (line.equals("checkend")) {149log2(" : returned string is 'checkend'");150break ;151} else if (!line.equals("checkready")) {152log3("ERROR: returned string is not 'checkready'");153testExitCode = FAILED;154break ;155}156157log1("new check: #" + i);158159//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part160161List listOfDebuggeeExecClasses = vm.classesByName(debuggeeName);162if (listOfDebuggeeExecClasses.size() != 1) {163testExitCode = FAILED;164log3("ERROR: listOfDebuggeeExecClasses.size() != 1");165break ;166}167ReferenceType execClass =168(ReferenceType) listOfDebuggeeExecClasses.get(0);169170Field fiplus1_1 = execClass.fieldByName("plus1_1");171Field fiplus1_2 = execClass.fieldByName("plus1_2");172173IntegerValue ivplus1_1 = (IntegerValue) execClass.getValue(fiplus1_1);174IntegerValue ivplus1_2 = (IntegerValue) execClass.getValue(fiplus1_2);175176int i2;177178for (i2 = 0; ; i2++) {179180int expresult = 0;181182log2("new check: #" + i2);183184switch (i2) {185186case 0: if (ivplus1_1.hashCode() != ivplus1_1.hashCode())187expresult = 1;188break;189190case 1: if (ivplus1_1.hashCode() != ivplus1_2.hashCode())191expresult = 1;192break;193194195default: expresult = 2;196break ;197}198199if (expresult == 2) {200log2(" test cases finished");201break ;202} else if (expresult == 1) {203log3("ERROR: expresult != true; check # = " + i);204testExitCode = FAILED;205}206}207//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~208}209log1(" TESTING ENDS");210211//-------------------------------------------------- test summary section212//------------------------------------------------- standard end section213214pipe.println("quit");215log2("waiting for the debuggee to finish ...");216debuggee.waitFor();217218int status = debuggee.getStatus();219if (status != PASSED + PASS_BASE) {220log3("debuggee returned UNEXPECTED exit status: " +221status + " != PASS_BASE");222testExitCode = FAILED;223} else {224log2("debuggee returned expected exit status: " +225status + " == PASS_BASE");226}227228if (testExitCode != PASSED) {229logHandler.complain("TEST FAILED");230}231return testExitCode;232}233}234235236