Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/ByteValue/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.ByteValue.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* ByteValue. <BR>36* <BR>37* The test checks up that results of the method <BR>38* <code>com.sun.jdi.ByteValue.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 byte plus1_1 = +1; <BR>45* public static byte plus1_2 = +1; <BR>46* <BR>47* which a debugger mirros as : <BR>48* <BR>49* ByteValue bvplus1_1; <BR>50* ByteValue bvplus1_2; <BR>51* <BR>52* the following is true: <BR>53* <BR>54* bvplus1_1.hashCode() == bvplus1_1.hashCode() <BR>55* bvplus1_1.hashCode() == bvplus1_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/ByteValue/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.ByteValue.hashCode.hashcode001a";103104//====================================================== test program105106static ArgumentHandler argsHandler;107static int testExitCode = PASSED;108109//------------------------------------------------------ common section110111private int runThis (String argv[], PrintStream out) {112113Debugee debugee;114115argsHandler = new ArgumentHandler(argv);116logHandler = new Log(out, argsHandler);117Binder binder = new Binder(argsHandler, logHandler);118119if (argsHandler.verbose()) {120debugee = binder.bindToDebugee(debuggeeName + " -vbs"); // *** tp121} else {122debugee = binder.bindToDebugee(debuggeeName); // *** tp123}124125IOPipe pipe = new IOPipe(debugee);126127debugee.redirectStderr(out);128log2("hashcode001a debugee launched");129debugee.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 = debugee.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 fbplus1_1 = execClass.fieldByName("plus1_1");171Field fbplus1_2 = execClass.fieldByName("plus1_2");172// Field fbminus1 = execClass.fieldByName("minus1");173// Field fsplus1 = execClass.fieldByName("shortplus1");174175ByteValue bvplus1_1 = (ByteValue) execClass.getValue(fbplus1_1);176ByteValue bvplus1_2 = (ByteValue) execClass.getValue(fbplus1_2);177// ByteValue bvminus1 = (ByteValue) execClass.getValue(fbminus1);178// ShortValue svplus1 = (ShortValue) execClass.getValue(fsplus1);179180int i2;181182for (i2 = 0; ; i2++) {183184int expresult = 0;185186log2("new check: #" + i2);187188switch (i2) {189190case 0: if (bvplus1_1.hashCode() != bvplus1_1.hashCode())191expresult = 1;192break;193194case 1: if (bvplus1_1.hashCode() != bvplus1_2.hashCode())195expresult = 1;196break;197198199default: expresult = 2;200break ;201}202203if (expresult == 2) {204log2(" test cases finished");205break ;206} else if (expresult == 1) {207log3("ERROR: expresult != true; check # = " + i);208testExitCode = FAILED;209}210}211//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~212}213log1(" TESTING ENDS");214215//-------------------------------------------------- test summary section216//------------------------------------------------- standard end section217218pipe.println("quit");219log2("waiting for the debugee finish ...");220debugee.waitFor();221222int status = debugee.getStatus();223if (status != PASSED + PASS_BASE) {224log3("debugee returned UNEXPECTED exit status: " +225status + " != PASS_BASE");226testExitCode = FAILED;227} else {228log2("debugee returned expected exit status: " +229status + " == PASS_BASE");230}231232if (testExitCode != PASSED) {233logHandler.complain("TEST FAILED");234}235return testExitCode;236}237}238239240