Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/ByteValue/equals/equals001.java
41160 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.equals;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.equals()</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* public static byte minus1 = -1; <BR>47* public static short shortplus1 = +1; <BR>48* <BR>49* which a debugger mirros as : <BR>50* <BR>51* ByteValue bvplus1_1; <BR>52* ByteValue bvplus1_2; <BR>53* ByteValue bvminus1; <BR>54* ShortValue svplus1; <BR>55* <BR>56* the following is true: <BR>57* <BR>58* bvplus1_1 == bvplus1_2 <BR>59* bvplus1_1 != bvminus1 <BR>60* bvplus1_1 != svplus1 <BR>61* <BR>62*/6364public class equals001 {6566//----------------------------------------------------- templete section67static final int PASSED = 0;68static final int FAILED = 2;69static final int PASS_BASE = 95;7071//----------------------------------------------------- templete parameters72static final String73sHeader1 = "\n==> nsk/jdi/ByteValue/equals/equals001",74sHeader2 = "--> equals001: ",75sHeader3 = "##> equals001: ";7677//----------------------------------------------------- main method7879public static void main (String argv[]) {80int result = run(argv, System.out);81System.exit(result + PASS_BASE);82}8384public static int run (String argv[], PrintStream out) {85return new equals001().runThis(argv, out);86}8788//-------------------------------------------------- log procedures8990private static boolean verbMode = false;9192private static Log logHandler;9394private static void log1(String message) {95logHandler.display(sHeader1 + message);96}97private static void log2(String message) {98logHandler.display(sHeader2 + message);99}100private static void log3(String message) {101logHandler.complain(sHeader3 + message);102}103104// ************************************************ test parameters105106private String debuggeeName =107"nsk.jdi.ByteValue.equals.equals001a";108109//====================================================== test program110111static ArgumentHandler argsHandler;112static int testExitCode = PASSED;113114//------------------------------------------------------ common section115116private int runThis (String argv[], PrintStream out) {117118Debugee debugee;119120argsHandler = new ArgumentHandler(argv);121logHandler = new Log(out, argsHandler);122Binder binder = new Binder(argsHandler, logHandler);123124if (argsHandler.verbose()) {125debugee = binder.bindToDebugee(debuggeeName + " -vbs"); // *** tp126} else {127debugee = binder.bindToDebugee(debuggeeName); // *** tp128}129130IOPipe pipe = new IOPipe(debugee);131132debugee.redirectStderr(out);133log2("equals001a debugee launched");134debugee.resume();135136String line = pipe.readln();137if ((line == null) || !line.equals("ready")) {138log3("signal received is not 'ready' but: " + line);139return FAILED;140} else {141log2("'ready' recieved");142}143144VirtualMachine vm = debugee.VM();145146//------------------------------------------------------ testing section147log1(" TESTING BEGINS");148149for (int i = 0; ; i++) {150pipe.println("newcheck");151line = pipe.readln();152153if (line.equals("checkend")) {154log2(" : returned string is 'checkend'");155break ;156} else if (!line.equals("checkready")) {157log3("ERROR: returned string is not 'checkready'");158testExitCode = FAILED;159break ;160}161162log1("new check: #" + i);163164//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part165166List listOfDebuggeeExecClasses = vm.classesByName(debuggeeName);167if (listOfDebuggeeExecClasses.size() != 1) {168testExitCode = FAILED;169log3("ERROR: listOfDebuggeeExecClasses.size() != 1");170break ;171}172ReferenceType execClass =173(ReferenceType) listOfDebuggeeExecClasses.get(0);174175Field fbplus1_1 = execClass.fieldByName("plus1_1");176Field fbplus1_2 = execClass.fieldByName("plus1_2");177Field fbminus1 = execClass.fieldByName("minus1");178Field fsplus1 = execClass.fieldByName("shortplus1");179180ByteValue bvplus1_1 = (ByteValue) execClass.getValue(fbplus1_1);181ByteValue bvplus1_2 = (ByteValue) execClass.getValue(fbplus1_2);182ByteValue bvminus1 = (ByteValue) execClass.getValue(fbminus1);183ShortValue svplus1 = (ShortValue) execClass.getValue(fsplus1);184185int i2;186187for (i2 = 0; ; i2++) {188189int expresult = 0;190191log2("new check: #" + i2);192193switch (i2) {194195case 0: if (!bvplus1_1.equals(bvplus1_2))196expresult = 1;197break;198199case 1: if (bvplus1_1.equals(bvminus1))200expresult = 1;201break;202203case 2: if (bvplus1_1.equals(svplus1))204expresult = 1;205break;206207208default: expresult = 2;209break ;210}211212if (expresult == 2) {213log2(" test cases finished");214break ;215} else if (expresult == 1) {216log3("ERROR: expresult != true; check # = " + i);217testExitCode = FAILED;218}219}220//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~221}222log1(" TESTING ENDS");223224//-------------------------------------------------- test summary section225//------------------------------------------------- standard end section226227pipe.println("quit");228log2("waiting for the debugee finish ...");229debugee.waitFor();230231int status = debugee.getStatus();232if (status != PASSED + PASS_BASE) {233log3("debugee returned UNEXPECTED exit status: " +234status + " != PASS_BASE");235testExitCode = FAILED;236} else {237log2("debugee returned expected exit status: " +238status + " == PASS_BASE");239}240241if (testExitCode != PASSED) {242logHandler.complain("TEST FAILED");243}244return testExitCode;245}246}247248249