Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdb/print/print002/print002.java
40951 views
/*1* Copyright (c) 2003, 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/print/print002.28* VM Testbase keywords: [quick, jpda, jdb]29* VM Testbase readme:30* DECSRIPTION31* This is a test for the 'print <expr>' command.32* The test checks if jdb correctly prints values for the following33* expressions:34* - arithmetic expression of local variables,35* - boolean expression of local variables,36* - string field deeply nested in class hierarchy.37* The test passes when all printed values are equal to expected ones.38* The test consists of two program:39* print002.java - launches jdb and debuggee, writes commands to jdb, reads the jdb output,40* print002a.java - the debugged application.41* COMMENTS42* The test replaces the nsk/jdb/print/print001 one.43* Test was fixed according to test bug:44* 4862693 NSK testcase nsk/jdb/print/print002 fails with operation not yet supported45*46* @library /vmTestbase47* /test/lib48* @build nsk.jdb.print.print002.print00249*50* @comment make sure print002a is compiled w/ full debug info51* @clean nsk.jdb.print.print002.print002a52* @compile -g:lines,source,vars print002a.java53*54* @run main/othervm55* nsk.jdb.print.print002.print00256* -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.print.print002;6768import nsk.share.*;69import nsk.share.jdb.*;7071import java.io.*;72import java.util.*;7374public class print002 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 print002().runTest(argv, out);85}8687static final String PACKAGE_NAME = "nsk.jdb.print.print002";88static final String TEST_CLASS = PACKAGE_NAME + ".print002";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{ "i + j", "8"},95{ "j - i", "4"},96{ "j * i", "12"},97{ "j / i", "3"},98// { "j % i", "0"},99// { "i++", "2"},100// { "++i", "3"},101// { "j--", "6"},102// { "--j", "5"},103// { "!b1 ", "false"},104// { "b2 && b1", "false"},105// { "b2 || b1", "true"},106{ "a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z.s", "foo" }107};108109protected void runCases() {110String[] reply;111Paragrep grep;112int count;113Vector v;114String found;115116jdb.setBreakpointInMethod(LAST_BREAK);117reply = jdb.receiveReplyFor(JdbCommand.cont);118119// to get out of lastBreak()120reply = jdb.receiveReplyFor(JdbCommand.step);121122for (int i = 0; i < checkedExpr.length; i++) {123if (!checkValue(checkedExpr[i][0], checkedExpr[i][1])) {124success = false;125}126}127128jdb.contToExit(1);129}130131private boolean checkValue (String expr, String value) {132Paragrep grep;133String[] reply;134String found;135Vector v;136boolean result = true;137138reply = jdb.receiveReplyFor(JdbCommand.print + expr);139grep = new Paragrep(reply);140found = grep.findFirst(value);141if (found.length() <= 0) {142log.complain("jdb failed to report value of expression: " + expr);143log.complain("\t expected : " + value + " ;\n\t reported: " + (reply.length > 0? reply[0]: ""));144result = false;145}146return result;147}148}149150151