Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdb/set/set002/set002.java
40951 views
/*1* Copyright (c) 2007, 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/set002.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* - element of array field,35* - local variable36* Probably needs to be merged with set00137* The jdb suspends the debuggee inside the method runIt and then tries38* to set new values for the fields and variables using checked command.39* Then the debuggee checks if modified fields/variables have expected40* values. If not, then special errorMessage variable is appended with41* the info of wrong values. The test passes when length of errorMessage42* is equal to 0, and fails otherwise.43* The test consists of two programs:44* set002.java - launches jdb and debuggee, writes commands to jdb, reads the jdb output,45* set002a.java - the debugged application.46*47* @library /vmTestbase48* /test/lib49* @build nsk.jdb.set.set002.set00250*51* @comment make sure set002a is compiled w/ full debug info52* @clean nsk.jdb.set.set002.set002a53* @compile -g:lines,source,vars set002a.java54*55* @run main/othervm56* nsk.jdb.set.set002.set00257* -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.set002;6869import nsk.share.*;70import nsk.share.jdb.*;7172import java.io.*;73import java.util.*;7475public class set002 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;8586return new set002().runTest(argv, out);87}8889static final String PACKAGE_NAME = "nsk.jdb.set.set002";90static final String TEST_CLASS = PACKAGE_NAME + ".set002";91static final String DEBUGGEE_CLASS = TEST_CLASS + "a";92static final String FIRST_BREAK = DEBUGGEE_CLASS + ".main";93static final String LAST_BREAK = DEBUGGEE_CLASS + ".lastBreak";9495static final String ERROR_MESSAGE = DEBUGGEE_CLASS + ".errorMessage";9697static final String[][] checkedExpr = { //not broken, can be run safely even if 4660158 is not fixed98{ DEBUGGEE_CLASS + "._set002a.myArrayField[0][0].line", "\"ABCDE\"" },99{ "localInt", "java.lang.Integer.MIN_VALUE"}100};101102protected void runCases() {103String[] reply;104Paragrep grep;105int count;106Vector v;107String found;108109jdb.setBreakpointInMethod(LAST_BREAK);110reply = jdb.receiveReplyFor(JdbCommand.cont);111112// to get out of lastBreak()113reply = jdb.receiveReplyFor(JdbCommand.step);114115// set values116for (int i = 0; i < checkedExpr.length; i++) {117reply = jdb.receiveReplyFor(JdbCommand.set + checkedExpr[i][0] + " = " + checkedExpr[i][1]);118}119120reply = jdb.receiveReplyFor(JdbCommand.cont);121// check value of debuggeeResult122reply = jdb.receiveReplyFor(JdbCommand.eval + ERROR_MESSAGE);123124//if everything is OK reply will look like this125// nsk.jdb.set.set002.set002a.errorMessage = ""126if (!reply[0].contains("\"\"")) {127log.complain("jdb failed to set value for expression(s): ");128for (int i = 0; i < reply.length; i++) {129log.complain(reply[i]);130}131success = false;132}133134jdb.contToExit(1);135}136}137138139