1 /* 2 * Copyright (c) 2002, 2020, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 25 /* 26 * @test 27 * 28 * @summary converted from VM Testbase nsk/jdb/clear/clear004. 29 * VM Testbase keywords: [jpda, jdb] 30 * VM Testbase readme: 31 * DECSRIPTION 32 * A positive test case for the 'clear <class_id:line>' command. 33 * The test sets 3 breakpoints and then clears one after the first 34 * breakpoint is reached. The tests verifies that jdb does not 35 * halt execution at the cleared breakpoint. 36 * COMMENTS 37 * This test functionally equals to nsk/jdb/clear/clear004 test and 38 * replaces it. 39 * 40 * @library /vmTestbase 41 * /test/lib 42 * @build nsk.jdb.clear.clear004.clear004a 43 * @run main/othervm 44 * nsk.jdb.clear.clear004.clear004 45 * -arch=${os.family}-${os.simpleArch} 46 * -waittime=5 47 * -debugee.vmkind=java 48 * -transport.address=dynamic 49 * -jdb=${test.jdk}/bin/jdb 50 * -java.options="${test.vm.opts} ${test.java.opts}" 51 * -workdir=. 52 * -debugee.vmkeys="${test.vm.opts} ${test.java.opts}" 53 */ 54 55 package nsk.jdb.clear.clear004; 56 57 import nsk.share.*; 58 import nsk.share.jdb.*; 59 60 import java.io.*; 61 import java.util.*; 62 63 public class clear004 extends JdbTest { 64 main(String argv[])65 public static void main (String argv[]) { 66 System.exit(run(argv, System.out) + JCK_STATUS_BASE); 67 } 68 run(String argv[], PrintStream out)69 public static int run(String argv[], PrintStream out) { 70 debuggeeClass = DEBUGGEE_CLASS; 71 firstBreak = FIRST_BREAK; 72 lastBreak = LAST_BREAK; 73 return new clear004().runTest(argv, out); 74 } 75 76 static final String PACKAGE_NAME = "nsk.jdb.clear.clear004"; 77 static final String TEST_CLASS = PACKAGE_NAME + ".clear004"; 78 static final String DEBUGGEE_CLASS = TEST_CLASS + "a"; 79 static final String FIRST_BREAK = DEBUGGEE_CLASS + ".main"; 80 static final String LAST_BREAK = DEBUGGEE_CLASS + ".lastBreak"; 81 static final String[] BREAKPOINTS = new String[] 82 { DEBUGGEE_CLASS + ":63", 83 DEBUGGEE_CLASS + ":67", 84 DEBUGGEE_CLASS + ":71" }; 85 static final String REMOVED_SAMPLE = "Removed:"; 86 runCases()87 protected void runCases() { 88 String[] reply; 89 Paragrep grep; 90 int count; 91 Vector v; 92 String found; 93 94 for (int i = 0; i < BREAKPOINTS.length; i++) { 95 log.display("Setting breakpoint at " + BREAKPOINTS[i]); 96 reply = jdb.receiveReplyFor(JdbCommand.stop_at + BREAKPOINTS[i]); 97 } 98 99 if (!checkClear (BREAKPOINTS[1])) { 100 success = false; 101 } 102 103 jdb.contToExit(3); 104 105 grep = new Paragrep(jdb.getTotalReply()); 106 count = grep.find(Jdb.BREAKPOINT_HIT); 107 if (count != 3) { 108 log.complain("Should hit 3 breakpoints."); 109 log.complain("Breakpoint hit count reported: " + count); 110 success = false; 111 } 112 113 if (!checkBreakpoint (BREAKPOINTS[1], grep)) { 114 success = false; 115 } 116 117 } 118 checkBreakpoint(String breakpoint, Paragrep grep)119 private boolean checkBreakpoint (String breakpoint, Paragrep grep) { 120 String found; 121 boolean result = true; 122 int count; 123 Vector v; 124 125 v = new Vector(); 126 v.add(Jdb.BREAKPOINT_HIT); 127 v.add(breakpoint); 128 129 found = grep.findFirst(v); 130 if (found.length() > 0) { 131 log.complain("Wrong hit at removed breakpoint at:" + breakpoint); 132 result = false; 133 } 134 return result; 135 } 136 checkClear(String breakpoint)137 private boolean checkClear (String breakpoint) { 138 Paragrep grep; 139 String found; 140 String[] reply; 141 boolean result = true; 142 int count; 143 Vector v; 144 145 v = new Vector(); 146 v.add(REMOVED_SAMPLE); 147 v.add(breakpoint); 148 149 log.display("Clearing breakpoint at: " + breakpoint); 150 reply = jdb.receiveReplyFor(JdbCommand.clear + breakpoint); 151 grep = new Paragrep(reply); 152 153 found = grep.findFirst(v); 154 if (found.length() == 0) { 155 log.complain("Failed to clear breakpoint at: " + breakpoint); 156 result = false; 157 } 158 return result; 159 } 160 } 161