Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdb/eval/eval001/eval001.java
40955 views
/*1* Copyright (c) 2002, 2020, 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*/222324/*25* @test26*27* @summary converted from VM Testbase nsk/jdb/eval/eval001.28* VM Testbase keywords: [jpda, jdb]29* VM Testbase readme:30* DECSRIPTION31* A positive test for the 'eval <expr>' command.32* The test checks if jdb correctly prints values for the following33* expressions:34* - static field,35* - instance field,36* - element of array field,37* - return value of a method,38* - arithmetic expression of local variables,39* - return value of public method of the java.lang.String class.40* The test passes when all printed values are equal to expected ones.41* The test consists of two program:42* eval001.java - launches jdb and debuggee, writes commands to jdb, reads the jdb output,43* eval001a.java - the debugged application.44* COMMENTS45*46* @library /vmTestbase47* /test/lib48* @build nsk.jdb.eval.eval001.eval00149*50* @comment make sure eval001a is compiled w/ full debug info51* @clean nsk.jdb.eval.eval001.eval001a52* @compile -g:lines,source,vars eval001a.java53*54* @run main/othervm55* nsk.jdb.eval.eval001.eval00156* -arch=${os.family}-${os.simpleArch}57* -waittime=558* -debugee.vmkind=java59* -transport.address=dynamic60* -jdb=${test.jdk}/bin/jdb61* -java.options="${test.vm.opts} ${test.java.opts}"62* -workdir=.63* -debugee.vmkeys="${test.vm.opts} ${test.java.opts}"64*/6566package nsk.jdb.eval.eval001;6768import nsk.share.*;69import nsk.share.jdb.*;7071import java.io.*;72import java.util.*;7374public class eval001 extends JdbTest {7576public static void main (String argv[]) {77System.exit(run(argv, System.out) + JCK_STATUS_BASE);78}7980public static int run(String argv[], PrintStream out) {81debuggeeClass = DEBUGGEE_CLASS;82firstBreak = FIRST_BREAK;83lastBreak = LAST_BREAK;84return new eval001().runTest(argv, out);85}8687static final String PACKAGE_NAME = "nsk.jdb.eval.eval001";88static final String TEST_CLASS = PACKAGE_NAME + ".eval001";89static final String DEBUGGEE_CLASS = TEST_CLASS + "a";90static final String FIRST_BREAK = DEBUGGEE_CLASS + ".main";91static final String LAST_BREAK = DEBUGGEE_CLASS + ".lastBreak";9293static final String[][] checkedExpr = {94{ DEBUGGEE_CLASS + ".myStaticField", "-2147483648" },95{ DEBUGGEE_CLASS + "._eval001a.myInstanceField", "9223372036854775807" },96{ DEBUGGEE_CLASS + "._eval001a.myArrayField[0][0].toString()", "ABCDE" },97{ DEBUGGEE_CLASS + "._eval001a.myMethod()", "2147483647" },98{ "myClass.toString().equals(\"abcde\")", "true"},99{ "i + j + k", "777"},100{ "new java.lang.String(\"Hello, World\").length()", "12"},101{ DEBUGGEE_CLASS + "._eval001a.testPrimitiveArray(test)", "1.0" }102};103104protected void runCases() {105String[] reply;106Paragrep grep;107int count;108Vector v;109String found;110111jdb.setBreakpointInMethod(LAST_BREAK);112reply = jdb.receiveReplyFor(JdbCommand.cont);113114// to get out of lastBreak()115reply = jdb.receiveReplyFor(JdbCommand.step);116117for (int i = 0; i < checkedExpr.length; i++) {118if (!checkValue(checkedExpr[i][0], checkedExpr[i][1])) {119success = false;120}121}122123jdb.contToExit(1);124}125126private boolean checkValue (String expr, String value) {127Paragrep grep;128String[] reply;129String found;130Vector v;131boolean result = true;132133reply = jdb.receiveReplyFor(JdbCommand.eval + expr);134grep = new Paragrep(reply);135found = grep.findFirst(value);136if (found.length() <= 0) {137log.complain("jdb failed to report value of expression: " + expr);138log.complain("expected : " + value + " ;\nreported: " + (reply.length > 0? reply[0]: ""));139result = false;140}141return result;142}143}144145146