Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/BooleanValue/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.BooleanValue.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* BooleanValue. <BR>36* <BR>37* The test checks up that results of the method <BR>38* <code>com.sun.jdi.BooleanValue.hashCode()</code> <BR>39* complies with its spec. <BR>40* The cases for testing are as follows : <BR>41* <BR>42* when a gebuggee executes the following : <BR>43* public static boolean bTrue1 = true; <BR>44* public static boolean bTrue2 = true; <BR>45* public static boolean bFalse1 = false; <BR>46* public static boolean bFalse2 = false; <BR>47* <BR>48* which a debugger mirros as : <BR>49* <BR>50* BooleanValue bvTrue1; <BR>51* BooleanValue bvTrue2; <BR>52* BooleanValue bvFalse1; <BR>53* BooleanValue bvFalse2; <BR>54* <BR>55* the following is true: <BR>56* <BR>57* bvTrue1.hashCode() == bvTrue1.hashCode() <BR>58* bvFalse1.hashCode() == bvFalse1.hashCode() <BR>59* bvTrue1.hashCode() == bvTrue2.hashCode() <BR>60* bvFalse1.hashCode() == bvFalse2.hashCode() <BR>61* bvTrue1.hashCode() != bvFalse1.hashCode() <BR>62* <BR>63*/6465public class hashcode001 {6667//----------------------------------------------------- templete section68static final int PASSED = 0;69static final int FAILED = 2;70static final int PASS_BASE = 95;7172//----------------------------------------------------- templete parameters73static final String74sHeader1 = "\n==> nsk/jdi/BooleanValue/hashCode/hashcode001",75sHeader2 = "--> hashcode001: ",76sHeader3 = "##> hashcode001: ";7778//----------------------------------------------------- main method7980public static void main (String argv[]) {81int result = run(argv, System.out);82System.exit(result + PASS_BASE);83}8485public static int run (String argv[], PrintStream out) {86return new hashcode001().runThis(argv, out);87}8889//-------------------------------------------------- log procedures9091private static boolean verbMode = false;9293private static Log logHandler;9495private static void log1(String message) {96logHandler.display(sHeader1 + message);97}98private static void log2(String message) {99logHandler.display(sHeader2 + message);100}101private static void log3(String message) {102logHandler.complain(sHeader3 + message);103}104105// ************************************************ test parameters106107private String debuggeeName =108"nsk.jdi.BooleanValue.hashCode.hashcode001a";109110//====================================================== test program111112static ArgumentHandler argsHandler;113static int testExitCode = PASSED;114115//------------------------------------------------------ common section116117private int runThis (String argv[], PrintStream out) {118119Debugee debugee;120121argsHandler = new ArgumentHandler(argv);122logHandler = new Log(out, argsHandler);123Binder binder = new Binder(argsHandler, logHandler);124125if (argsHandler.verbose()) {126debugee = binder.bindToDebugee(debuggeeName + " -vbs"); // *** tp127} else {128debugee = binder.bindToDebugee(debuggeeName); // *** tp129}130131IOPipe pipe = new IOPipe(debugee);132133debugee.redirectStderr(out);134log2("hashcode001a debugee launched");135debugee.resume();136137String line = pipe.readln();138if ((line == null) || !line.equals("ready")) {139log3("signal received is not 'ready' but: " + line);140return FAILED;141} else {142log2("'ready' recieved");143}144145VirtualMachine vm = debugee.VM();146147//------------------------------------------------------ testing section148log1(" TESTING BEGINS");149150for (int i = 0; ; i++) {151pipe.println("newcheck");152line = pipe.readln();153154if (line.equals("checkend")) {155log2(" : returned string is 'checkend'");156break ;157} else if (!line.equals("checkready")) {158log3("ERROR: returned string is not 'checkready'");159testExitCode = FAILED;160break ;161}162163log1("new check: #" + i);164165//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part166167List listOfDebuggeeExecClasses = vm.classesByName(debuggeeName);168if (listOfDebuggeeExecClasses.size() != 1) {169testExitCode = FAILED;170log3("ERROR: listOfDebuggeeExecClasses.size() != 1");171break ;172}173ReferenceType execClass =174(ReferenceType) listOfDebuggeeExecClasses.get(0);175176Field fTrue1 = execClass.fieldByName("bTrue1");177Field fTrue2 = execClass.fieldByName("bTrue2");178Field fFalse1 = execClass.fieldByName("bFalse1");179Field fFalse2 = execClass.fieldByName("bFalse2");180181BooleanValue bvTrue1 = (BooleanValue) execClass.getValue(fTrue1);182BooleanValue bvTrue2 = (BooleanValue) execClass.getValue(fTrue2);183BooleanValue bvFalse1 = (BooleanValue) execClass.getValue(fFalse1);184BooleanValue bvFalse2 = (BooleanValue) execClass.getValue(fFalse2);185186int i2;187188for (i2 = 0; ; i2++) {189190int expresult = 0;191192log2("new check: #" + i2);193194switch (i2) {195196case 0: if (bvTrue1.hashCode() != bvTrue1.hashCode())197expresult = 1;198break;199200case 1: if (bvFalse1.hashCode() != bvFalse1.hashCode())201expresult = 1;202break;203204case 2: if (bvTrue1.hashCode() != bvTrue2.hashCode())205expresult = 1;206break;207208case 3: if (bvFalse1.hashCode() != bvFalse2.hashCode())209expresult = 1;210break;211212case 4: if (bvTrue1.hashCode() == bvFalse1.hashCode())213expresult = 1;214break;215216217default: expresult = 2;218break ;219}220221if (expresult == 2) {222log2(" test cases finished");223break ;224} else if (expresult == 1) {225log3("ERROR: expresult != 1; check # = " + i2);226testExitCode = FAILED;227}228}229230//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~231}232log1(" TESTING ENDS");233234//-------------------------------------------------- test summary section235//------------------------------------------------- standard end section236237pipe.println("quit");238log2("waiting for the debugee finish ...");239debugee.waitFor();240241int status = debugee.getStatus();242if (status != PASSED + PASS_BASE) {243log3("debugee returned UNEXPECTED exit status: " +244status + " != PASS_BASE");245testExitCode = FAILED;246} else {247log2("debugee returned expected exit status: " +248status + " == PASS_BASE");249}250251if (testExitCode != PASSED) {252logHandler.complain("TEST FAILED");253}254return testExitCode;255}256}257258259