Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdb/watch/watch002/watch002.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/watch/watch002.28* VM Testbase keywords: [jpda, jdb]29* VM Testbase readme:30* DECSRIPTION31* A positive test case for the 'watch all <class id>.<field name>' command.32* There are two test cases:33* - access and modification watch set for the fields defined in class,34* - access and modification watch set for the fields defined in inner class.35* The debugged application invokes the methods in which all checked fields36* participate in assigned expressions as well as are assigned.37* The test passes jdb correctly reports on access and modification events for38* all checked fields. Correct report message in jdb stdout should contain full39* name of the field and "access encountered" or "will be" words.40* The test consists of two program:41* watch002.java - launches jdb and debuggee, writes commands to jdb, reads the jdb output,42* watch002a.java - the debugged application.43* COMMENTS44* Test fixed according to test bug:45* 5045859 TEST_BUG: some JDB tests do not recognize JDB prompt46*47* @library /vmTestbase48* /test/lib49* @build nsk.jdb.watch.watch002.watch002a50* @run main/othervm51* nsk.jdb.watch.watch002.watch00252* -arch=${os.family}-${os.simpleArch}53* -waittime=554* -debugee.vmkind=java55* -transport.address=dynamic56* -jdb=${test.jdk}/bin/jdb57* -java.options="${test.vm.opts} ${test.java.opts}"58* -workdir=.59* -debugee.vmkeys="${test.vm.opts} ${test.java.opts}"60*/6162package nsk.jdb.watch.watch002;6364import nsk.share.*;65import nsk.share.jdb.*;6667import java.io.*;68import java.util.*;6970public class watch002 extends JdbTest {7172public static void main (String argv[]) {73System.exit(run(argv, System.out) + JCK_STATUS_BASE);74}7576public static int run(String argv[], PrintStream out) {77debuggeeClass = DEBUGGEE_CLASS;78firstBreak = FIRST_BREAK;79lastBreak = LAST_BREAK;80compoundPromptIdent = COMPOUND_PROMPT_IDENT;81return new watch002().runTest(argv, out);82}8384static final String PACKAGE_NAME = "nsk.jdb.watch.watch002";85static final String TEST_CLASS = PACKAGE_NAME + ".watch002";86static final String DEBUGGEE_CLASS = TEST_CLASS + "a";87static final String DEBUGGEE_CLASS2 = DEBUGGEE_CLASS + "$CheckedFields";88static final String FIRST_BREAK = DEBUGGEE_CLASS + ".main";89static final String LAST_BREAK = DEBUGGEE_CLASS + ".breakHere";90static final String COMPOUND_PROMPT_IDENT = "main";9192static String[] checkedFields = { "FS0", "FS1" };93static String[] checkedFields2 = { "FP1", "FU1", "FR1", "FT1", "FV1" };9495protected void runCases() {96String[] reply;97Paragrep grep;98int count;99Vector v;100String found;101102jdb.setBreakpointInMethod(LAST_BREAK);103104reply = jdb.receiveReplyFor(JdbCommand.fields + DEBUGGEE_CLASS);105106reply = jdb.receiveReplyFor(JdbCommand.fields + DEBUGGEE_CLASS2);107108watchFields (DEBUGGEE_CLASS, checkedFields);109watchFields (DEBUGGEE_CLASS2, checkedFields2);110111jdb.contToExit((checkedFields.length *2) + (checkedFields2.length *2) + 2);112113reply = jdb.getTotalReply();114if (!checkFields (DEBUGGEE_CLASS, reply, checkedFields)) {115success = false;116}117if (!checkFields (DEBUGGEE_CLASS2, reply, checkedFields2)) {118success = false;119}120}121122private void watchFields (String className, String[] checkedFields) {123String[] reply;124125for (int i = 0; i < checkedFields.length; i++) {126reply = jdb.receiveReplyFor(JdbCommand.watch + " all " + className + "." + checkedFields[i]);127}128129}130131private boolean checkFields (String className, String[] reply, String[] checkedFields) {132Paragrep grep;133String found;134boolean result = true;135int count;136Vector v = new Vector();137138grep = new Paragrep(reply);139v.add("access encountered");140for (int i = 0; i < checkedFields.length; i++) {141v.removeAllElements();142v.add("access encountered");143v.add(className + "." + checkedFields[i]);144145found = grep.findFirst(v);146if (found.length() == 0) {147log.complain("Failed to report access to field " + className + "." + checkedFields[i]);148result = false;149}150151v.removeAllElements();152v.add("will be");153v.add(className + "." + checkedFields[i]);154155found = grep.findFirst(v);156if (found.length() == 0) {157log.complain("Failed to report modification of field " + className + "." + checkedFields[i]);158result = false;159}160}161return result;162}163}164165166