Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdb/watch/watch001/watch001.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/watch001.28* VM Testbase keywords: [jpda, jdb]29* VM Testbase readme:30* DECSRIPTION31* A positive test case for the 'watch access <class id>.<field name>' command.32* There are two test cases:33* - access watch set for the fields defined in class,34* - access 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.37* The test passes jdb correctly reports on access event for all checked fields.38* Correct report message in jdb stdout should contain full name of the field39* and "access encountered" words.40* The test consists of two program:41* watch001.java - launches jdb and debuggee, writes commands to jdb, reads the jdb output,42* watch001a.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.watch001.watch001a50* @run main/othervm51* nsk.jdb.watch.watch001.watch00152* -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.watch001;6364import nsk.share.*;65import nsk.share.jdb.*;6667import java.io.*;68import java.util.*;6970public class watch001 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 watch001().runTest(argv, out);82}8384static final String PACKAGE_NAME = "nsk.jdb.watch.watch001";85static final String TEST_CLASS = PACKAGE_NAME + ".watch001";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 = { "FP0", "FU1", "FR0", "FT1", "FV0" };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 + checkedFields2.length + 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 + " access " + 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}150}151return result;152}153}154155156