Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/ByteValue/value/value001.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.value;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.value()</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 smallest = Byte.MIN_VALUE; <BR>45* public static byte zero = 0; <BR>46* public static byte largest = Byte.MAX_VALUE; <BR>47* <BR>48* which a debugger mirros as : <BR>49* <BR>50* ByteValue bvsmallest; <BR>51* ByteValue bvzero; <BR>52* ByteValue bvlargest; <BR>53* <BR>54* the following is true: <BR>55* <BR>56* bvsmallest.value() == Byte.MIN_VALUE <BR>57* bvzero.value() == 0 <BR>58* bvlargest.value() == Byte.MAX_VALUE <BR>59* <BR>60*/6162public class value001 {6364//----------------------------------------------------- templete section65static final int PASSED = 0;66static final int FAILED = 2;67static final int PASS_BASE = 95;6869//----------------------------------------------------- templete parameters70static final String71sHeader1 = "\n==> nsk/jdi/ByteValue/value/value001",72sHeader2 = "--> value001: ",73sHeader3 = "##> value001: ";7475//----------------------------------------------------- main method7677public static void main (String argv[]) {78int result = run(argv, System.out);79System.exit(result + PASS_BASE);80}8182public static int run (String argv[], PrintStream out) {83return new value001().runThis(argv, out);84}8586//-------------------------------------------------- log procedures8788private static boolean verbMode = false;8990private static Log logHandler;9192private static void log1(String message) {93logHandler.display(sHeader1 + message);94}95private static void log2(String message) {96logHandler.display(sHeader2 + message);97}98private static void log3(String message) {99logHandler.complain(sHeader3 + message);100}101102// ************************************************ test parameters103104private String debuggeeName =105"nsk.jdi.ByteValue.value.value001a";106107//====================================================== test program108109static ArgumentHandler argsHandler;110static int testExitCode = PASSED;111112//------------------------------------------------------ common section113114private int runThis (String argv[], PrintStream out) {115116Debugee debugee;117118argsHandler = new ArgumentHandler(argv);119logHandler = new Log(out, argsHandler);120Binder binder = new Binder(argsHandler, logHandler);121122if (argsHandler.verbose()) {123debugee = binder.bindToDebugee(debuggeeName + " -vbs"); // *** tp124} else {125debugee = binder.bindToDebugee(debuggeeName); // *** tp126}127128IOPipe pipe = new IOPipe(debugee);129130debugee.redirectStderr(out);131log2("value001a debugee launched");132debugee.resume();133134String line = pipe.readln();135if ((line == null) || !line.equals("ready")) {136log3("signal received is not 'ready' but: " + line);137return FAILED;138} else {139log2("'ready' recieved");140}141142VirtualMachine vm = debugee.VM();143144//------------------------------------------------------ testing section145log1(" TESTING BEGINS");146147for (int i = 0; ; i++) {148pipe.println("newcheck");149line = pipe.readln();150151if (line.equals("checkend")) {152log2(" : returned string is 'checkend'");153break ;154} else if (!line.equals("checkready")) {155log3("ERROR: returned string is not 'checkready'");156testExitCode = FAILED;157break ;158}159160log1("new check: #" + i);161162//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part163164List listOfDebuggeeExecClasses = vm.classesByName(debuggeeName);165if (listOfDebuggeeExecClasses.size() != 1) {166testExitCode = FAILED;167log3("ERROR: listOfDebuggeeExecClasses.size() != 1");168break ;169}170ReferenceType execClass =171(ReferenceType) listOfDebuggeeExecClasses.get(0);172173Field fbsmallest = execClass.fieldByName("smallest");174Field fbzero = execClass.fieldByName("zero");175Field fblargest = execClass.fieldByName("largest");176177ByteValue bvsmallest = (ByteValue) execClass.getValue(fbsmallest);178ByteValue bvzero = (ByteValue) execClass.getValue(fbzero);179ByteValue bvlargest = (ByteValue) execClass.getValue(fblargest);180181int i2;182183for (i2 = 0; ; i2++) {184185int expresult = 0;186187log2("new check: #" + i2);188189switch (i2) {190191case 0: if (bvsmallest.value() != Byte.MIN_VALUE)192expresult = 1;193break;194195case 1: if (bvzero.value() != 0)196expresult = 1;197break;198199case 2: if (bvlargest.value() != Byte.MAX_VALUE)200expresult = 1;201break;202203204default: expresult = 2;205break ;206}207208if (expresult == 2) {209log2(" test cases finished");210break ;211} else if (expresult == 1) {212log3("ERROR: expresult != true; check # = " + i);213testExitCode = FAILED;214}215}216//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~217}218log1(" TESTING ENDS");219220//-------------------------------------------------- test summary section221//------------------------------------------------- standard end section222223pipe.println("quit");224log2("waiting for the debugee finish ...");225debugee.waitFor();226227int status = debugee.getStatus();228if (status != PASSED + PASS_BASE) {229log3("debugee returned UNEXPECTED exit status: " +230status + " != PASS_BASE");231testExitCode = FAILED;232} else {233log2("debugee returned expected exit status: " +234status + " == PASS_BASE");235}236237if (testExitCode != PASSED) {238logHandler.complain("TEST FAILED");239}240return testExitCode;241}242}243244245