1 /*
2  * Copyright (c) 2002, 2018, 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  * @run driver jdk.test.lib.FileInstaller . .
43  * @build nsk.jdb.clear.clear004.clear004
44  *        nsk.jdb.clear.clear004.clear004a
45  * @run main/othervm PropertyResolvingWrapper nsk.jdb.clear.clear004.clear004
46  *      -arch=${os.family}-${os.simpleArch}
47  *      -waittime=5
48  *      -debugee.vmkind=java
49  *      -transport.address=dynamic
50  *      -jdb=${test.jdk}/bin/jdb
51  *      -java.options="${test.vm.opts} ${test.java.opts}"
52  *      -workdir=.
53  *      -debugee.vmkeys="${test.vm.opts} ${test.java.opts}"
54  */
55 
56 package nsk.jdb.clear.clear004;
57 
58 import nsk.share.*;
59 import nsk.share.jdb.*;
60 
61 import java.io.*;
62 import java.util.*;
63 
64 public class clear004 extends JdbTest {
65 
main(String argv[])66     public static void main (String argv[]) {
67         System.exit(run(argv, System.out) + JCK_STATUS_BASE);
68     }
69 
run(String argv[], PrintStream out)70     public static int run(String argv[], PrintStream out) {
71         debuggeeClass =  DEBUGGEE_CLASS;
72         firstBreak = FIRST_BREAK;
73         lastBreak = LAST_BREAK;
74         return new clear004().runTest(argv, out);
75     }
76 
77     static final String PACKAGE_NAME     = "nsk.jdb.clear.clear004";
78     static final String TEST_CLASS       = PACKAGE_NAME + ".clear004";
79     static final String DEBUGGEE_CLASS   = TEST_CLASS + "a";
80     static final String FIRST_BREAK      = DEBUGGEE_CLASS + ".main";
81     static final String LAST_BREAK       = DEBUGGEE_CLASS + ".lastBreak";
82     static final String[] BREAKPOINTS = new String[]
83         { DEBUGGEE_CLASS + ":63",
84           DEBUGGEE_CLASS + ":67",
85           DEBUGGEE_CLASS + ":71" };
86     static final String REMOVED_SAMPLE   = "Removed:";
87 
runCases()88     protected void runCases() {
89         String[] reply;
90         Paragrep grep;
91         int count;
92         Vector v;
93         String found;
94 
95         for (int i = 0; i < BREAKPOINTS.length; i++) {
96            log.display("Setting breakpoint at " + BREAKPOINTS[i]);
97            reply = jdb.receiveReplyFor(JdbCommand.stop_at + BREAKPOINTS[i]);
98         }
99 
100         if (!checkClear (BREAKPOINTS[1])) {
101             success = false;
102         }
103 
104         jdb.contToExit(3);
105 
106         grep = new Paragrep(jdb.getTotalReply());
107         count = grep.find(Jdb.BREAKPOINT_HIT);
108         if (count != 3) {
109             log.complain("Should hit 3 breakpoints.");
110             log.complain("Breakpoint hit count reported: " + count);
111             success = false;
112         }
113 
114         if (!checkBreakpoint (BREAKPOINTS[1], grep)) {
115             success = false;
116         }
117 
118     }
119 
checkBreakpoint(String breakpoint, Paragrep grep)120     private boolean checkBreakpoint (String breakpoint, Paragrep grep) {
121         String found;
122         boolean result = true;
123         int count;
124         Vector v;
125 
126         v = new Vector();
127         v.add(Jdb.BREAKPOINT_HIT);
128         v.add(breakpoint);
129 
130         found = grep.findFirst(v);
131         if (found.length() > 0) {
132             log.complain("Wrong hit at removed breakpoint at:" + breakpoint);
133             result = false;
134         }
135         return result;
136     }
137 
checkClear(String breakpoint)138     private boolean checkClear (String breakpoint) {
139         Paragrep grep;
140         String found;
141         String[] reply;
142         boolean result = true;
143         int count;
144         Vector v;
145 
146         v = new Vector();
147         v.add(REMOVED_SAMPLE);
148         v.add(breakpoint);
149 
150         log.display("Clearing breakpoint at: " + breakpoint);
151         reply = jdb.receiveReplyFor(JdbCommand.clear + breakpoint);
152         grep = new Paragrep(reply);
153 
154         found = grep.findFirst(v);
155         if (found.length() == 0) {
156             log.complain("Failed to clear breakpoint at: " + breakpoint);
157             result = false;
158         }
159         return result;
160     }
161 }
162