Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdb/unwatch/unwatch002/unwatch002.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/unwatch/unwatch002.28* VM Testbase keywords: [jpda, jdb]29* VM Testbase readme:30* DECSRIPTION31* A positive test case for the 'unwatch all <class id>.<field name>' command.32* There are two test cases:33* - unwatch all for the fields defined in class,34* - unwatch all for the fields defined in inner class.35* At first phase of testing the full watch is set for all checked fields with36* "watch all" command. Then debugged application invokes the methods (updateFields)37* in which all checked fields participate in assigned expressions as well as are38* assigned to. Thus the jdb should report the access event and modification event39* for the fields.40* At seconds phase of testing all watch monitors are deleted with the tested41* command. Then updateFields methods are invoked in debuggee again.42* The test passes jdb reports only once an access and modification events for43* every checked fields. Correct report message in jdb stdout should contain full44* name of the field and "access encountered" or "will be" words.45* The test consists of two program:46* watch002.java - launches jdb and debuggee, writes commands to jdb, reads the jdb output,47* watch002a.java - the debugged application.48* COMMENTS49*50* @library /vmTestbase51* /test/lib52* @build nsk.jdb.unwatch.unwatch002.unwatch002a53* @run main/othervm54* nsk.jdb.unwatch.unwatch002.unwatch00255* -arch=${os.family}-${os.simpleArch}56* -waittime=557* -debugee.vmkind=java58* -transport.address=dynamic59* -jdb=${test.jdk}/bin/jdb60* -java.options="${test.vm.opts} ${test.java.opts}"61* -workdir=.62* -debugee.vmkeys="${test.vm.opts} ${test.java.opts}"63*/6465package nsk.jdb.unwatch.unwatch002;6667import nsk.share.*;68import nsk.share.jdb.*;6970import java.io.*;71import java.util.*;7273public class unwatch002 extends JdbTest {7475public static void main (String argv[]) {76System.exit(run(argv, System.out) + JCK_STATUS_BASE);77}7879public static int run(String argv[], PrintStream out) {80debuggeeClass = DEBUGGEE_CLASS;81firstBreak = FIRST_BREAK;82lastBreak = LAST_BREAK;83return new unwatch002().runTest(argv, out);84}8586static final String PACKAGE_NAME = "nsk.jdb.unwatch.unwatch002";87static final String TEST_CLASS = PACKAGE_NAME + ".unwatch002";88static final String DEBUGGEE_CLASS = TEST_CLASS + "a";89static final String DEBUGGEE_CLASS2 = DEBUGGEE_CLASS + "$CheckedFields";90static final String FIRST_BREAK = DEBUGGEE_CLASS + ".main";91static final String LAST_BREAK = DEBUGGEE_CLASS + ".breakHere";92static final String expectedPrompt = "main[1]";9394static String[] checkedFields = { "FS1" };95static String[] checkedFields2 = { "FT1", "FV1" };9697protected void runCases() {98String[] reply;99Paragrep grep;100int count;101Vector v;102String found;103104jdb.setBreakpointInMethod(LAST_BREAK);105106reply = jdb.receiveReplyFor(JdbCommand.fields + DEBUGGEE_CLASS);107108reply = jdb.receiveReplyFor(JdbCommand.fields + DEBUGGEE_CLASS2);109110watchFields (DEBUGGEE_CLASS, checkedFields);111watchFields (DEBUGGEE_CLASS2, checkedFields2);112113// jdb.contToExit((checkedFields.length *2) + (checkedFields2.length *2) + 2);114for (int i = 0; i < (checkedFields.length *2 + checkedFields2.length*2 + 2); i++) {115reply = jdb.receiveReplyForWithMessageWait(JdbCommand.cont, expectedPrompt);116}117118unwatchFields (DEBUGGEE_CLASS, checkedFields);119unwatchFields (DEBUGGEE_CLASS2, checkedFields2);120121// excessive number of cont commands in case if unwatch command does not work.122jdb.contToExit(checkedFields.length*2 + checkedFields2.length*2 + 1);123124reply = jdb.getTotalReply();125if (!checkFields (DEBUGGEE_CLASS, reply, checkedFields)) {126success = false;127}128if (!checkFields (DEBUGGEE_CLASS2, reply, checkedFields2)) {129success = false;130}131}132133private void watchFields (String className, String[] checkedFields) {134String[] reply;135136for (int i = 0; i < checkedFields.length; i++) {137reply = jdb.receiveReplyFor(JdbCommand.watch + " all " + className + "." + checkedFields[i]);138}139140}141142private void unwatchFields (String className, String[] checkedFields) {143String[] reply;144145for (int i = 0; i < checkedFields.length; i++) {146reply = jdb.receiveReplyFor(JdbCommand.unwatch + " all " + className + "." + checkedFields[i]);147}148149}150151private boolean checkFields (String className, String[] reply, String[] checkedFields) {152Paragrep grep;153String found;154boolean result = true;155int count;156Vector v = new Vector();157158grep = new Paragrep(reply);159v.add("access encountered");160for (int i = 0; i < checkedFields.length; i++) {161v.removeAllElements();162v.add("access encountered");163v.add(className + "." + checkedFields[i]);164165count = grep.find(v);166if (count != 1) {167log.complain("jdb reported wrong number of access to the field " + className + "." + checkedFields[i]);168log.complain("Should be 1, reported: " + count);169result = false;170}171172v.removeAllElements();173v.add(className + "." + checkedFields[i]);174v.add("will be instance");175176count = grep.find(v);177if (count != 1) {178log.complain("jdb reported wrong number of modification of the field " + className + "." + checkedFields[i]);179log.complain("Should be 1, reported: " + count);180result = false;181}182183}184return result;185}186}187188189