Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdb/clear/clear004/clear004.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/clear004.28* VM Testbase keywords: [jpda, jdb]29* VM Testbase readme:30* DECSRIPTION31* A positive test case for the 'clear <class_id:line>' command.32* The test sets 3 breakpoints and then clears one after the first33* breakpoint is reached. The tests verifies that jdb does not34* halt execution at the cleared breakpoint.35* COMMENTS36* This test functionally equals to nsk/jdb/clear/clear004 test and37* replaces it.38*39* @library /vmTestbase40* /test/lib41* @build nsk.jdb.clear.clear004.clear004a42* @run main/othervm43* nsk.jdb.clear.clear004.clear00444* -arch=${os.family}-${os.simpleArch}45* -waittime=546* -debugee.vmkind=java47* -transport.address=dynamic48* -jdb=${test.jdk}/bin/jdb49* -java.options="${test.vm.opts} ${test.java.opts}"50* -workdir=.51* -debugee.vmkeys="${test.vm.opts} ${test.java.opts}"52*/5354package nsk.jdb.clear.clear004;5556import nsk.share.*;57import nsk.share.jdb.*;5859import java.io.*;60import java.util.*;6162public class clear004 extends JdbTest {6364public static void main (String argv[]) {65System.exit(run(argv, System.out) + JCK_STATUS_BASE);66}6768public static int run(String argv[], PrintStream out) {69debuggeeClass = DEBUGGEE_CLASS;70firstBreak = FIRST_BREAK;71lastBreak = LAST_BREAK;72return new clear004().runTest(argv, out);73}7475static final String PACKAGE_NAME = "nsk.jdb.clear.clear004";76static final String TEST_CLASS = PACKAGE_NAME + ".clear004";77static final String DEBUGGEE_CLASS = TEST_CLASS + "a";78static final String FIRST_BREAK = DEBUGGEE_CLASS + ".main";79static final String LAST_BREAK = DEBUGGEE_CLASS + ".lastBreak";80static final String[] BREAKPOINTS = new String[]81{ DEBUGGEE_CLASS + ":63",82DEBUGGEE_CLASS + ":67",83DEBUGGEE_CLASS + ":71" };84static final String REMOVED_SAMPLE = "Removed:";8586protected void runCases() {87String[] reply;88Paragrep grep;89int count;90Vector v;91String found;9293for (int i = 0; i < BREAKPOINTS.length; i++) {94log.display("Setting breakpoint at " + BREAKPOINTS[i]);95reply = jdb.receiveReplyFor(JdbCommand.stop_at + BREAKPOINTS[i]);96}9798if (!checkClear (BREAKPOINTS[1])) {99success = false;100}101102jdb.contToExit(3);103104grep = new Paragrep(jdb.getTotalReply());105count = grep.find(Jdb.BREAKPOINT_HIT);106if (count != 3) {107log.complain("Should hit 3 breakpoints.");108log.complain("Breakpoint hit count reported: " + count);109success = false;110}111112if (!checkBreakpoint (BREAKPOINTS[1], grep)) {113success = false;114}115116}117118private boolean checkBreakpoint (String breakpoint, Paragrep grep) {119String found;120boolean result = true;121int count;122Vector v;123124v = new Vector();125v.add(Jdb.BREAKPOINT_HIT);126v.add(breakpoint);127128found = grep.findFirst(v);129if (found.length() > 0) {130log.complain("Wrong hit at removed breakpoint at:" + breakpoint);131result = false;132}133return result;134}135136private boolean checkClear (String breakpoint) {137Paragrep grep;138String found;139String[] reply;140boolean result = true;141int count;142Vector v;143144v = new Vector();145v.add(REMOVED_SAMPLE);146v.add(breakpoint);147148log.display("Clearing breakpoint at: " + breakpoint);149reply = jdb.receiveReplyFor(JdbCommand.clear + breakpoint);150grep = new Paragrep(reply);151152found = grep.findFirst(v);153if (found.length() == 0) {154log.complain("Failed to clear breakpoint at: " + breakpoint);155result = false;156}157return result;158}159}160161162