Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/DoubleValue/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.DoubleValue.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* DoubleValue. <BR>36* <BR>37* The test checks up that results of the method <BR>38* <code>com.sun.jdi.DoubleValue.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 double plus1_1 = +1d; <BR>45* public static double plus1_2 = +1d; <BR>46* public static double pos_largest = Double.MAX_VALUE; <BR>47* <BR>48* which a debugger mirros as : <BR>49* <BR>50* DoubleValue dvplus1_1; <BR>51* DoubleValue dvplus1_2; <BR>52* DoubleValue dvpos_largest; <BR>53* <BR>54* the following is true: <BR>55* <BR>56* dvpos_largest.hashCode() == dvpos_largest.hashCode() <BR>57* dvplus1_1.hashCode() == dvplus1_2.hashCode() <BR>58* <BR>59*/6061public class hashcode001 {6263//----------------------------------------------------- templete section64static final int PASSED = 0;65static final int FAILED = 2;66static final int PASS_BASE = 95;6768//----------------------------------------------------- templete parameters69static final String70sHeader1 = "\n==> nsk/jdi/DoubleValue/hashCode/hashcode001",71sHeader2 = "--> hashcode001: ",72sHeader3 = "##> hashcode001: ";7374//----------------------------------------------------- main method7576public static void main (String argv[]) {77int result = run(argv, System.out);78System.exit(result + PASS_BASE);79}8081public static int run (String argv[], PrintStream out) {82return new hashcode001().runThis(argv, out);83}8485//-------------------------------------------------- log procedures8687private static boolean verbMode = false;8889private static Log logHandler;9091private static void log1(String message) {92logHandler.display(sHeader1 + message);93}94private static void log2(String message) {95logHandler.display(sHeader2 + message);96}97private static void log3(String message) {98logHandler.complain(sHeader3 + message);99}100101// ************************************************ test parameters102103private String debuggeeName =104"nsk.jdi.DoubleValue.hashCode.hashcode001a";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 listOfDebuggeeExecClasses = vm.classesByName(debuggeeName);164if (listOfDebuggeeExecClasses.size() != 1) {165testExitCode = FAILED;166log3("ERROR: listOfDebuggeeExecClasses.size() != 1");167break ;168}169ReferenceType execClass =170(ReferenceType) listOfDebuggeeExecClasses.get(0);171172Field fdplus1_1 = execClass.fieldByName("plus1_1");173Field fdplus1_2 = execClass.fieldByName("plus1_2");174Field fdpos_largest = execClass.fieldByName("pos_largest");175176DoubleValue dvplus1_1 = (DoubleValue) execClass.getValue(fdplus1_1);177DoubleValue dvplus1_2 = (DoubleValue) execClass.getValue(fdplus1_2);178DoubleValue dvpos_largest =179(DoubleValue) execClass.getValue(fdpos_largest);180181int i2;182183for (i2 = 0; ; i2++) {184185int expresult = 0;186187log2("new check: #" + i2);188189switch (i2) {190191case 0: if (dvpos_largest.hashCode() != dvpos_largest.hashCode())192expresult = 1;193break;194195case 1: if (dvplus1_1.hashCode() != dvplus1_2.hashCode())196expresult = 1;197break;198199200default: expresult = 2;201break ;202}203204if (expresult == 2) {205log2(" test cases finished");206break ;207} else if (expresult == 1) {208log3("ERROR: expresult != true; check # = " + i);209testExitCode = FAILED;210}211}212//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~213}214log1(" TESTING ENDS");215216//-------------------------------------------------- test summary section217//------------------------------------------------- standard end section218219pipe.println("quit");220log2("waiting for the debuggee to finish ...");221debuggee.waitFor();222223int status = debuggee.getStatus();224if (status != PASSED + PASS_BASE) {225log3("debuggee returned UNEXPECTED exit status: " +226status + " != PASS_BASE");227testExitCode = FAILED;228} else {229log2("debuggee returned expected exit status: " +230status + " == PASS_BASE");231}232233if (testExitCode != PASSED) {234logHandler.complain("TEST FAILED");235}236return testExitCode;237}238}239240241