Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdb/unwatch/unwatch001/unwatch001.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/unwatch001.28* VM Testbase keywords: [jpda, jdb]29* VM Testbase readme:30* DECSRIPTION31* A positive test case for the 'unwatch access <class id>.<field name>' command.32* There are two test cases:33* - unwatch access for the fields defined in class,34* - unwatch access for the fields defined in inner class.35* At first phase of testing the access watch is set for all checked fields with36* "watch access" command. Then debugged application invokes the methods (updateFields)37* in which all checked fields participate in assigned expressions. Thus the jdb38* should report the access event for the fields.39* At seconds phase of testing all access watch monitors are deleted with40* the tested command. Then updateFields methods are invoked in debuggee again.41* The test passes jdb reports only once an access event for every checked fields.42* Correct report message in jdb stdout should contain full name of the field43* and "access encountered" words.44* The test consists of two program:45* watch001.java - launches jdb and debuggee, writes commands to jdb, reads the jdb output,46* watch001a.java - the debugged application.47* COMMENTS48*49* @library /vmTestbase50* /test/lib51* @build nsk.jdb.unwatch.unwatch001.unwatch001a52* @run main/othervm53* nsk.jdb.unwatch.unwatch001.unwatch00154* -arch=${os.family}-${os.simpleArch}55* -waittime=556* -debugee.vmkind=java57* -transport.address=dynamic58* -jdb=${test.jdk}/bin/jdb59* -java.options="${test.vm.opts} ${test.java.opts}"60* -workdir=.61* -debugee.vmkeys="${test.vm.opts} ${test.java.opts}"62*/6364package nsk.jdb.unwatch.unwatch001;6566import nsk.share.*;67import nsk.share.jdb.*;6869import java.io.*;70import java.util.*;7172public class unwatch001 extends JdbTest {7374public static void main (String argv[]) {75System.exit(run(argv, System.out) + JCK_STATUS_BASE);76}7778public static int run(String argv[], PrintStream out) {79debuggeeClass = DEBUGGEE_CLASS;80firstBreak = FIRST_BREAK;81lastBreak = LAST_BREAK;82return new unwatch001().runTest(argv, out);83}8485static final String PACKAGE_NAME = "nsk.jdb.unwatch.unwatch001";86static final String TEST_CLASS = PACKAGE_NAME + ".unwatch001";87static final String DEBUGGEE_CLASS = TEST_CLASS + "a";88static final String DEBUGGEE_CLASS2 = DEBUGGEE_CLASS + "$CheckedFields";89static final String FIRST_BREAK = DEBUGGEE_CLASS + ".main";90static final String LAST_BREAK = DEBUGGEE_CLASS + ".breakHere";9192static String[] checkedFields = { "fS1", "FS0" };93static String[] checkedFields2 = { "fP1", "fU1", "fR1"};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);110111for (int i = 0; i < (checkedFields.length + checkedFields2.length + 2); i++) {112reply = jdb.receiveReplyFor(JdbCommand.cont);113}114115unwatchFields (DEBUGGEE_CLASS, checkedFields);116unwatchFields (DEBUGGEE_CLASS2, checkedFields2);117118// excessive number of cont commands in case if unwatch command does not work.119jdb.contToExit(checkedFields.length + checkedFields2.length + 1);120121reply = jdb.getTotalReply();122if (!checkFields (DEBUGGEE_CLASS, reply, checkedFields)) {123success = false;124}125if (!checkFields (DEBUGGEE_CLASS2, reply, checkedFields2)) {126success = false;127}128}129130private void watchFields (String className, String[] checkedFields) {131String[] reply;132133for (int i = 0; i < checkedFields.length; i++) {134reply = jdb.receiveReplyFor(JdbCommand.watch + " access " + className + "." + checkedFields[i]);135}136137}138139private void unwatchFields (String className, String[] checkedFields) {140String[] reply;141142for (int i = 0; i < checkedFields.length; i++) {143reply = jdb.receiveReplyFor(JdbCommand.unwatch + " access " + className + "." + checkedFields[i]);144}145146}147148private boolean checkFields (String className, String[] reply, String[] checkedFields) {149Paragrep grep;150String found;151boolean result = true;152int count;153Vector v = new Vector();154155grep = new Paragrep(reply);156v.add("access encountered");157for (int i = 0; i < checkedFields.length; i++) {158v.removeAllElements();159v.add("access encountered");160v.add(className + "." + checkedFields[i]);161162count = grep.find(v);163if (count != 1) {164log.complain("jdb reported wrong number of access to the field " + className + "." + checkedFields[i]);165log.complain("Should be 1, reported: " + count);166result = false;167}168}169return result;170}171}172173174