Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdb/set/set001/set001.java
40951 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/set/set001.28* VM Testbase keywords: [jpda, jdb]29* VM Testbase readme:30* DECSRIPTION31* A positive test for the 'set <lvalue> = <expr>' command.32* The test checks if jdb correctly sets value for the following33* fields and variables:34* - static field,35* - instance field36* The jdb suspends the debuggee inside the method runIt and then tries37* to set new values for the fields and variables using checked command.38* Then the debuggee checks if modified fields/variables have expected39* values. If not, then special errorMessage variable is appended with40* the info of wrong values. The test passes when length of errorMessage41* is equal to 0, and fails otherwise.42* The test consists of two program:43* set001.java - launches jdb and debuggee, writes commands to jdb, reads the jdb output,44* set001a.java - the debugged application.45* COMMENTS46*47* @library /vmTestbase48* /test/lib49* @build nsk.jdb.set.set001.set00150*51* @comment make sure set001a is compiled w/ full debug info52* @clean nsk.jdb.set.set001.set001a53* @compile -g:lines,source,vars set001a.java54*55* @run main/othervm56* nsk.jdb.set.set001.set00157* -arch=${os.family}-${os.simpleArch}58* -waittime=559* -debugee.vmkind=java60* -transport.address=dynamic61* -jdb=${test.jdk}/bin/jdb62* -java.options="${test.vm.opts} ${test.java.opts}"63* -workdir=.64* -debugee.vmkeys="${test.vm.opts} ${test.java.opts}"65*/6667package nsk.jdb.set.set001;6869import nsk.share.*;70import nsk.share.jdb.*;7172import java.io.*;73import java.util.*;7475public class set001 extends JdbTest {7677public static void main (String argv[]) {78System.exit(run(argv, System.out) + JCK_STATUS_BASE);79}8081public static int run(String argv[], PrintStream out) {82debuggeeClass = DEBUGGEE_CLASS;83firstBreak = FIRST_BREAK;84lastBreak = LAST_BREAK;85return new set001().runTest(argv, out);86}8788static final String PACKAGE_NAME = "nsk.jdb.set.set001";89static final String TEST_CLASS = PACKAGE_NAME + ".set001";90static final String DEBUGGEE_CLASS = TEST_CLASS + "a";91static final String FIRST_BREAK = DEBUGGEE_CLASS + ".main";92static final String LAST_BREAK = DEBUGGEE_CLASS + ".lastBreak";9394static final String ERROR_MESSAGE = DEBUGGEE_CLASS + ".errorMessage";9596static final String[][] checkedExpr = {97{ DEBUGGEE_CLASS + ".myStaticField", "-2147483648" },98{ DEBUGGEE_CLASS + "._set001a.myInstanceField", "9223372036854775807" },99};100101protected void runCases() {102String[] reply;103Paragrep grep;104int count;105Vector v;106String found;107108jdb.setBreakpointInMethod(LAST_BREAK);109reply = jdb.receiveReplyFor(JdbCommand.cont);110111// to get out of lastBreak()112reply = jdb.receiveReplyFor(JdbCommand.step);113114// set values115for (int i = 0; i < checkedExpr.length; i++) {116reply = jdb.receiveReplyFor(JdbCommand.set + checkedExpr[i][0] + " = " + checkedExpr[i][1]);117}118119reply = jdb.receiveReplyFor(JdbCommand.cont);120// check value of debuggeeResult121reply = jdb.receiveReplyFor(JdbCommand.eval + ERROR_MESSAGE);122//if everything is OK reply will look like this123// nsk.jdb.set.set001.set001a.errorMessage = ""124if (!reply[0].contains("\"\"")) {125log.complain("jdb failed to set value for expression(s): ");126for (int i = 0; i < reply.length; i++) {127log.complain(reply[i]);128}129success = false;130}131132jdb.contToExit(1);133}134}135136137