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/uncaught_exception/uncaught_exception002.
29  * VM Testbase keywords: [jpda, jdb]
30  * VM Testbase readme:
31  * DESCRIPTION
32  *  This goal of this test is to verify that when the debugee
33  *  throws an uncaught exception, jdb halts the execution at the point
34  *  where the exception was thrown. The test verifies the following:
35  *    - the locals variables at this point can be printed out,
36  *    - "Exception occured" message is printed out.
37  *  The test consists of two parts:
38  *    uncaught_exception002.java  - test driver, i.e. launches jdb and debuggee,
39  *                       writes commands to jdb, reads the jdb output,
40  *    uncaught_exception002a.java - the debugged application.
41  * COMMENTS
42  *  The test is functionally equal to
43  *  nsk/jdb/uncaught_exception/uncaught_exception002 test and replaces it.
44  *  Modified due to fix of the bug:
45  *  4818762 TEST_BUG: two jdb test incorrectly check debuggee exit code
46  *
47  * @library /vmTestbase
48  *          /test/lib
49  * @run driver jdk.test.lib.FileInstaller . .
50  * @build nsk.jdb.uncaught_exception.uncaught_exception002.uncaught_exception002
51  *
52  * @comment make sure uncaught_exception002a is compiled w/ full debug info
53  * @clean nsk.jdb.uncaught_exception.uncaught_exception002.uncaught_exception002a
54  * @compile -g:lines,source,vars uncaught_exception002a.java
55  *
56  * @run main/othervm PropertyResolvingWrapper
57  *      nsk.jdb.uncaught_exception.uncaught_exception002.uncaught_exception002
58  *      -arch=${os.family}-${os.simpleArch}
59  *      -waittime=5
60  *      -debugee.vmkind=java
61  *      -transport.address=dynamic
62  *      -jdb=${test.jdk}/bin/jdb
63  *      -java.options="${test.vm.opts} ${test.java.opts}"
64  *      -workdir=.
65  *      -debugee.vmkeys="${test.vm.opts} ${test.java.opts}"
66  */
67 
68 package nsk.jdb.uncaught_exception.uncaught_exception002;
69 
70 import nsk.share.*;
71 import nsk.share.jdb.*;
72 
73 import java.io.*;
74 import java.util.*;
75 
76 public class uncaught_exception002 extends JdbTest {
77 
main(String argv[])78     public static void main (String argv[]) {
79         System.exit(run(argv, System.out) + JCK_STATUS_BASE);
80     }
81 
run(String argv[], PrintStream out)82     public static int run(String argv[], PrintStream out) {
83         debuggeeClass =  DEBUGGEE_CLASS;
84         firstBreak = FIRST_BREAK;
85         lastBreak = LAST_BREAK;
86         return new uncaught_exception002(true).runTest(argv, out);
87     }
88 
89     static final String PACKAGE_NAME = "nsk.jdb.uncaught_exception.uncaught_exception002";
90     static final String TEST_CLASS = PACKAGE_NAME + ".uncaught_exception002";
91     static final String DEBUGGEE_CLASS = TEST_CLASS + "a";
92     static final String FIRST_BREAK        = DEBUGGEE_CLASS + ".main";
93     static final String LAST_BREAK         = DEBUGGEE_CLASS + ".lastBreak";
94 
95     static final String[] FRAMES = new String[] {
96         DEBUGGEE_CLASS + ".func",
97         DEBUGGEE_CLASS + ".runIt",
98         DEBUGGEE_CLASS + ".main"                };
99 
uncaught_exception002(boolean debuggeeShouldFail)100     public uncaught_exception002 (boolean debuggeeShouldFail) {
101         super(debuggeeShouldFail);
102     }
103 
runCases()104     protected void runCases() {
105         String[] reply;
106         Paragrep grep;
107         int count;
108         Vector v;
109         String found;
110 
111         jdb.receiveReplyFor(JdbCommand.cont);
112         jdb.receiveReplyFor(JdbCommand.locals);
113         jdb.contToExit(1);
114 
115         reply = jdb.getTotalReply();
116         grep = new Paragrep(reply);
117 
118         v = new Vector();
119         v.add("Exception occurred");
120         v.add(PACKAGE_NAME + ".TenMultipleException");
121         if (grep.find(v) == 0) {
122             failure("jdb does not reported of TenMultipleException occurence");
123         }
124 
125         v = new Vector();
126         v.add("localVar");
127         v.add("1234");
128         if (grep.find(v) == 0) {
129             failure("Local variable of stack frame the exception was thrown " +
130                 "is not accessible");
131         }
132     }
133 
checkStop()134     private boolean checkStop () {
135         Paragrep grep;
136         String[] reply;
137         String found;
138         Vector v;
139         boolean result = true;
140 
141         return result;
142     }
143 }
144