Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/DoubleValue/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.DoubleValue.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* DoubleValue. <BR>36* <BR>37* The test checks up that results of the method <BR>38* <code>com.sun.jdi.DoubleValue.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 double pos_inf = Double.POSITIVE_INFINITY; <BR>45* public static double pos_zero = 0.0d; <BR>46* public static double neg_zero = -0.0d; <BR>47* public static double neg_inf = Double.NEGATIVE_INFINITY; <BR>48* public static double pos_largest = Double.MAX_VALUE; <BR>49* public static double pos_smallest = Double.MIN_VALUE; <BR>50* public static double neg_largest = -Double.MAX_VALUE; <BR>51* public static double neg_smallest = -Double.MIN_VALUE; <BR>52* public static double double_nan = Double.NaN; <BR>53* <BR>54* which a debugger mirros as : <BR>55* <BR>56* DoubleValue dvpos_inf; <BR>57* DoubleValue dvpos_zero; <BR>58* DoubleValue dvneg_zero; <BR>59* DoubleValue dvneg_inf; <BR>60* DoubleValue dvpos_largest; <BR>61* DoubleValue dvpos_smallest; <BR>62* DoubleValue dvneg_largest; <BR>63* DoubleValue dvneg_smallest; <BR>64* DoubleValue dvdouble_nan; <BR>65* <BR>66* the following is true: <BR>67* <BR>68* dvneg_inf.value() == Double.NEGATIVE_INFINITY <BR>69* dvneg_largest.value() == -Double.MAX_VALUE <BR>70* dvneg_smallest.value() == -Double.MIN_VALUE <BR>71* dvneg_zero.value() == -0.0d <BR>72* dvpos_zero.value() == 0.0d <BR>73* dvpos_smallest.value() == Double.MIN_VALUE <BR>74* dvpos_largest.value() == Double.MAX_VALUE <BR>75* dvpos_inf.value() == Double.POSITIVE_INFINITY <BR>76* dvdouble_nan.value() != dvdouble_nan.value() <BR>77* <BR>78*/7980public class value001 {8182//----------------------------------------------------- templete section83static final int PASSED = 0;84static final int FAILED = 2;85static final int PASS_BASE = 95;8687//----------------------------------------------------- templete parameters88static final String89sHeader1 = "\n==> nsk/jdi/DoubleValue/value/value001",90sHeader2 = "--> value001: ",91sHeader3 = "##> value001: ";9293//----------------------------------------------------- main method9495public static void main (String argv[]) {96int result = run(argv, System.out);97System.exit(result + PASS_BASE);98}99100public static int run (String argv[], PrintStream out) {101return new value001().runThis(argv, out);102}103104//-------------------------------------------------- log procedures105106private static boolean verbMode = false;107108private static Log logHandler;109110private static void log1(String message) {111logHandler.display(sHeader1 + message);112}113private static void log2(String message) {114logHandler.display(sHeader2 + message);115}116private static void log3(String message) {117logHandler.complain(sHeader3 + message);118}119120// ************************************************ test parameters121122private String debuggeeName =123"nsk.jdi.DoubleValue.value.value001a";124125//====================================================== test program126127static ArgumentHandler argsHandler;128static int testExitCode = PASSED;129130//------------------------------------------------------ common section131132private int runThis (String argv[], PrintStream out) {133134Debugee debuggee;135136argsHandler = new ArgumentHandler(argv);137logHandler = new Log(out, argsHandler);138Binder binder = new Binder(argsHandler, logHandler);139140if (argsHandler.verbose()) {141debuggee = binder.bindToDebugee(debuggeeName + " -vbs"); // *** tp142} else {143debuggee = binder.bindToDebugee(debuggeeName); // *** tp144}145146IOPipe pipe = new IOPipe(debuggee);147148debuggee.redirectStderr(out);149log2("value001a debuggee launched");150debuggee.resume();151152String line = pipe.readln();153if ((line == null) || !line.equals("ready")) {154log3("signal received is not 'ready' but: " + line);155return FAILED;156} else {157log2("'ready' recieved");158}159160VirtualMachine vm = debuggee.VM();161162//------------------------------------------------------ testing section163log1(" TESTING BEGINS");164165for (int i = 0; ; i++) {166pipe.println("newcheck");167line = pipe.readln();168169if (line.equals("checkend")) {170log2(" : returned string is 'checkend'");171break ;172} else if (!line.equals("checkready")) {173log3("ERROR: returned string is not 'checkready'");174testExitCode = FAILED;175break ;176}177178log1("new check: #" + i);179180//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part181182List listOfDebuggeeExecClasses = vm.classesByName(debuggeeName);183if (listOfDebuggeeExecClasses.size() != 1) {184testExitCode = FAILED;185log3("ERROR: listOfDebuggeeExecClasses.size() != 1");186break ;187}188ReferenceType execClass =189(ReferenceType) listOfDebuggeeExecClasses.get(0);190191Field fdneg_inf = execClass.fieldByName("neg_inf");192Field fdneg_largest = execClass.fieldByName("neg_largest");193Field fdneg_smallest = execClass.fieldByName("neg_smallest");194Field fdneg_zero = execClass.fieldByName("neg_zero");195Field fdpos_zero = execClass.fieldByName("pos_zero");196Field fdpos_smallest = execClass.fieldByName("pos_smallest");197Field fdpos_largest = execClass.fieldByName("pos_largest");198Field fdpos_inf = execClass.fieldByName("pos_inf");199Field fddouble_nan = execClass.fieldByName("double_nan");200201DoubleValue dvneg_inf = (DoubleValue) execClass.getValue(fdneg_inf);202DoubleValue dvneg_largest = (DoubleValue) execClass.getValue(fdneg_largest);203DoubleValue dvneg_smallest = (DoubleValue) execClass.getValue(fdneg_smallest);204DoubleValue dvneg_zero = (DoubleValue) execClass.getValue(fdneg_zero);205DoubleValue dvpos_zero = (DoubleValue) execClass.getValue(fdpos_zero);206DoubleValue dvpos_smallest = (DoubleValue) execClass.getValue(fdpos_smallest);207DoubleValue dvpos_largest = (DoubleValue) execClass.getValue(fdpos_largest);208DoubleValue dvpos_inf = (DoubleValue) execClass.getValue(fdpos_inf);209DoubleValue dvdouble_nan = (DoubleValue) execClass.getValue(fddouble_nan);210211int i2;212213for (i2 = 0; ; i2++) {214215int expresult = 0;216217log2("new check: #" + i2);218219switch (i2) {220221case 0: if (dvneg_inf.value() != Double.NEGATIVE_INFINITY)222expresult = 1;223break;224225case 1: if (dvneg_largest.value() != -Double.MAX_VALUE)226expresult = 1;227break;228229case 2: if (dvneg_smallest.value() != -Double.MIN_VALUE)230expresult = 1;231break;232233case 3: if (dvneg_zero.value() != -0.0d)234expresult = 1;235break;236237case 4: if (dvpos_zero.value() != 0.0d)238expresult = 1;239break;240241case 5: if (dvpos_smallest.value() != Double.MIN_VALUE)242expresult = 1;243break;244245case 6: if (dvpos_largest.value() != Double.MAX_VALUE)246expresult = 1;247break;248249case 7: if (dvpos_inf.value() != Double.POSITIVE_INFINITY)250expresult = 1;251break;252253case 8: if ( !(dvdouble_nan.value() != dvdouble_nan.value()) )254expresult = 1;255break;256257258default: expresult = 2;259break ;260}261262if (expresult == 2) {263log2(" test cases finished");264break ;265} else if (expresult == 1) {266log3("ERROR: expresult != true; check # = " + i);267testExitCode = FAILED;268}269}270//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~271}272log1(" TESTING ENDS");273274//-------------------------------------------------- test summary section275//------------------------------------------------- standard end section276277pipe.println("quit");278log2("waiting for the debuggee to finish ...");279debuggee.waitFor();280281int status = debuggee.getStatus();282if (status != PASSED + PASS_BASE) {283log3("debuggee returned UNEXPECTED exit status: " +284status + " != PASS_BASE");285testExitCode = FAILED;286} else {287log2("debuggee returned expected exit status: " +288status + " == PASS_BASE");289}290291if (testExitCode != PASSED) {292logHandler.complain("TEST FAILED");293}294return testExitCode;295}296}297298299