Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdb/clear/clear002/clear002.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/clear/clear002.28* VM Testbase keywords: [jpda, jdb]29* VM Testbase readme:30* DECSRIPTION31* A positive test case for the 'clear <class_id>.<method>' command.32* The test sets 3 breakpoints and then clears two of them after the33* first breakpoint is reached. The tests verifies that jdb does not34* halt execution at the cleared breakpoint.35* COMMENTS36*37* @library /vmTestbase38* /test/lib39* @build nsk.jdb.clear.clear002.clear002a40* @run main/othervm41* nsk.jdb.clear.clear002.clear00242* -arch=${os.family}-${os.simpleArch}43* -waittime=544* -debugee.vmkind=java45* -transport.address=dynamic46* -jdb=${test.jdk}/bin/jdb47* -java.options="${test.vm.opts} ${test.java.opts}"48* -workdir=.49* -debugee.vmkeys="${test.vm.opts} ${test.java.opts}"50*/5152package nsk.jdb.clear.clear002;5354import nsk.share.*;55import nsk.share.jdb.*;5657import java.io.*;58import java.util.*;5960public class clear002 extends JdbTest {6162public static void main (String argv[]) {63System.exit(run(argv, System.out) + JCK_STATUS_BASE);64}6566public static int run(String argv[], PrintStream out) {67debuggeeClass = DEBUGGEE_CLASS;68firstBreak = FIRST_BREAK;69lastBreak = LAST_BREAK;70return new clear002().runTest(argv, out);71}7273static final String PACKAGE_NAME = "nsk.jdb.clear.clear002";74static final String TEST_CLASS = PACKAGE_NAME + ".clear002";75static final String DEBUGGEE_CLASS = TEST_CLASS + "a";76static final String FIRST_BREAK = DEBUGGEE_CLASS + ".main";77static final String LAST_BREAK = DEBUGGEE_CLASS + ".lastBreak";78static final String METHOD_TO_STOP = DEBUGGEE_CLASS + ".func5";79static final String METHOD1_TO_CLEAR = DEBUGGEE_CLASS + ".func4";80static final String METHOD2_TO_CLEAR = DEBUGGEE_CLASS + "$A.func7";81static final String REMOVED_SAMPLE = "Removed:";8283protected void runCases() {84String[] reply;85Paragrep grep;86int count;87Vector v;88String found;8990log.display("Setting breakpoint in method: " + METHOD1_TO_CLEAR);91jdb.setBreakpointInMethod(METHOD1_TO_CLEAR);9293log.display("Setting breakpoint in method: " + METHOD2_TO_CLEAR);94jdb.setBreakpointInMethod(METHOD2_TO_CLEAR);9596log.display("Setting breakpoint in method: " + METHOD_TO_STOP);97jdb.setBreakpointInMethod(METHOD_TO_STOP);9899if (!checkClear (METHOD1_TO_CLEAR)) {100success = false;101}102103if (!checkClear (METHOD2_TO_CLEAR)) {104success = false;105}106107jdb.contToExit(2);108109grep = new Paragrep(jdb.getTotalReply());110count = grep.find(Jdb.BREAKPOINT_HIT);111if (count != 2) {112log.complain("Should hit 2 breakpoints.");113log.complain("Breakpoint hit count reported: " + count);114success = false;115}116117if (!checkBreakpoint (METHOD1_TO_CLEAR, grep)) {118success = false;119}120121if (!checkBreakpoint (METHOD2_TO_CLEAR, grep)) {122success = false;123}124}125126private boolean checkBreakpoint (String methodName, Paragrep grep) {127String found;128boolean result = true;129int count;130Vector v;131132v = new Vector();133v.add(Jdb.BREAKPOINT_HIT);134v.add(methodName);135136found = grep.findFirst(v);137if (found.length() > 0) {138log.complain("Wrong hit at removed breakpoint in method:" + methodName);139result = false;140}141return result;142}143144private boolean checkClear (String methodName) {145Paragrep grep;146String found;147String[] reply;148boolean result = true;149int count;150Vector v;151152v = new Vector();153v.add(REMOVED_SAMPLE);154v.add(methodName);155156log.display("Clearing breakpoint in method:" + methodName);157reply = jdb.receiveReplyFor(JdbCommand.clear + methodName);158grep = new Paragrep(reply);159160found = grep.findFirst(v);161if (found.length() == 0) {162log.complain("Failed to clear breakpoint in method: " + methodName);163result = false;164}165return result;166}167}168169170