Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/CharValue/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.CharValue.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* CharValue. <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 executes the following : <BR>43* public static char char_a_1 = 'a'; <BR>44* public static char char_a_2 = 'a'; <BR>45* public static char char_smallest = Character.MIN_VALUE; <BR>46* <BR>47* which a debugger mirros as : <BR>48* <BR>49* CharValue cvchar_a_1; <BR>50* CharValue cvchar_a_2; <BR>51* CharValue cvchar_smallest; <BR>52* <BR>53* the following is true: <BR>54* <BR>55* cvchar_smallest == cvchar_smallest <BR>56* cvchar_a_1 == cvchar_a_2 <BR>57* <BR>58*/5960public class hashcode001 {6162//----------------------------------------------------- templete section63static final int PASSED = 0;64static final int FAILED = 2;65static final int PASS_BASE = 95;6667//----------------------------------------------------- templete parameters68static final String69sHeader1 = "\n==> nsk/jdi/CharValue/hashCode/hashcode001",70sHeader2 = "--> hashcode001: ",71sHeader3 = "##> hashcode001: ";7273//----------------------------------------------------- main method7475public static void main (String argv[]) {76int result = run(argv, System.out);77System.exit(result + PASS_BASE);78}7980public static int run (String argv[], PrintStream out) {81return new hashcode001().runThis(argv, out);82}8384//-------------------------------------------------- log procedures8586private static boolean verbMode = false;8788private static Log logHandler;8990private static void log1(String message) {91logHandler.display(sHeader1 + message);92}93private static void log2(String message) {94logHandler.display(sHeader2 + message);95}96private static void log3(String message) {97logHandler.complain(sHeader3 + message);98}99100// ************************************************ test parameters101102private String debuggeeName =103"nsk.jdi.CharValue.hashCode.hashcode001a";104105//====================================================== test program106107static ArgumentHandler argsHandler;108static int testExitCode = PASSED;109110//------------------------------------------------------ common section111112private int runThis (String argv[], PrintStream out) {113114Debugee debuggee;115116argsHandler = new ArgumentHandler(argv);117logHandler = new Log(out, argsHandler);118Binder binder = new Binder(argsHandler, logHandler);119120if (argsHandler.verbose()) {121debuggee = binder.bindToDebugee(debuggeeName + " -vbs"); // *** tp122} else {123debuggee = binder.bindToDebugee(debuggeeName); // *** tp124}125126IOPipe pipe = new IOPipe(debuggee);127128debuggee.redirectStderr(out);129log2("hashcode001a debuggee launched");130debuggee.resume();131132String line = pipe.readln();133if ((line == null) || !line.equals("ready")) {134log3("signal received is not 'ready' but: " + line);135return FAILED;136} else {137log2("'ready' recieved");138}139140VirtualMachine vm = debuggee.VM();141142//------------------------------------------------------ testing section143log1(" TESTING BEGINS");144145for (int i = 0; ; i++) {146pipe.println("newcheck");147line = pipe.readln();148149if (line.equals("checkend")) {150log2(" : returned string is 'checkend'");151break ;152} else if (!line.equals("checkready")) {153log3("ERROR: returned string is not 'checkready'");154testExitCode = FAILED;155break ;156}157158log1("new check: #" + i);159160//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part161162List listOfDebuggeeExecClasses = vm.classesByName(debuggeeName);163if (listOfDebuggeeExecClasses.size() != 1) {164testExitCode = FAILED;165log3("ERROR: listOfDebuggeeExecClasses.size() != 1");166break ;167}168ReferenceType execClass =169(ReferenceType) listOfDebuggeeExecClasses.get(0);170171Field fcchar_smallest = execClass.fieldByName("smallest");172Field fcchar_a_1 = execClass.fieldByName("char_a_1");173Field fcchar_a_2 = execClass.fieldByName("char_a_2");174175CharValue cvchar_smallest = (CharValue) execClass.getValue(fcchar_smallest);176CharValue cvchar_a_1 = (CharValue) execClass.getValue(fcchar_a_1);177CharValue cvchar_a_2 = (CharValue) execClass.getValue(fcchar_a_2);178179180int i2;181182for (i2 = 0; ; i2++) {183184int expresult = 0;185186log2("new check: #" + i2);187188switch (i2) {189190case 0: if (!cvchar_smallest.equals(cvchar_smallest))191expresult = 1;192break;193194case 1: if (!cvchar_a_1.equals(cvchar_a_2))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 debuggee finish ...");220debuggee.waitFor();221222int status = debuggee.getStatus();223if (status != PASSED + PASS_BASE) {224log3("debuggee returned UNEXPECTED exit status: " +225status + " != PASS_BASE");226testExitCode = FAILED;227} else {228log2("debuggee returned expected exit status: " +229status + " == PASS_BASE");230}231232if (testExitCode != PASSED) {233logHandler.complain("TEST FAILED");234}235return testExitCode;236}237}238239240