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/where/where004.
29  * VM Testbase keywords: [jpda, jdb]
30  * VM Testbase readme:
31  * DECSRIPTION
32  *  A test case for the 'where' command. The test sets a breakpoint
33  *  at func5() in debugged `where004a` class and then runs debugee.
34  *  Once, execution comes to a halt at func5(), the 'where' command
35  *  is issued to the debugger. The test passes if items printed in
36  *  stack trace are equal to expected ones.
37  * COMMENTS
38  *  This test functionally equals to nsk/jdb/where/where001 test
39  *  and replaces it.
40  *
41  * @library /vmTestbase
42  *          /test/lib
43  * @run driver jdk.test.lib.FileInstaller . .
44  * @build nsk.jdb.where.where004.where004
45  *        nsk.jdb.where.where004.where004a
46  * @run main/othervm PropertyResolvingWrapper nsk.jdb.where.where004.where004
47  *      -arch=${os.family}-${os.simpleArch}
48  *      -waittime=5
49  *      -debugee.vmkind=java
50  *      -transport.address=dynamic
51  *      -jdb=${test.jdk}/bin/jdb
52  *      -java.options="${test.vm.opts} ${test.java.opts}"
53  *      -workdir=.
54  *      -debugee.vmkeys="${test.vm.opts} ${test.java.opts}"
55  */
56 
57 package nsk.jdb.where.where004;
58 
59 import nsk.share.*;
60 import nsk.share.jdb.*;
61 
62 import java.io.*;
63 import java.util.*;
64 
65 public class where004 extends JdbTest {
66 
main(String argv[])67     public static void main (String argv[]) {
68         System.exit(run(argv, System.out) + JCK_STATUS_BASE);
69     }
70 
run(String argv[], PrintStream out)71     public static int run(String argv[], PrintStream out) {
72         debuggeeClass =  DEBUGGEE_CLASS;
73         firstBreak = FIRST_BREAK;
74         lastBreak = LAST_BREAK;
75         return new where004().runTest(argv, out);
76     }
77 
78     static final String PACKAGE_NAME     = "nsk.jdb.where.where004";
79     static final String TEST_CLASS       = PACKAGE_NAME + ".where004";
80     static final String DEBUGGEE_CLASS   = TEST_CLASS + "a";
81     static final String FIRST_BREAK      = DEBUGGEE_CLASS + ".main";
82     static final String LAST_BREAK       = DEBUGGEE_CLASS + ".lastBreak";
83 
84     static final String[][] FRAMES = new String[][] {
85         {DEBUGGEE_CLASS + ".func5", "71"},
86         {DEBUGGEE_CLASS + ".func4", "67"},
87         {DEBUGGEE_CLASS + ".func3", "63"},
88         {DEBUGGEE_CLASS + ".func2", "59"},
89         {DEBUGGEE_CLASS + ".func1", "55"},
90         {DEBUGGEE_CLASS + ".runIt", "48"},
91         {DEBUGGEE_CLASS + ".main",  "39"}
92                                                 };
runCases()93     protected void runCases() {
94         String[] reply;
95         Paragrep grep;
96         int count;
97         Vector v;
98         String found;
99 
100         jdb.receiveReplyFor(JdbCommand.stop_in + DEBUGGEE_CLASS + ".func5");
101         jdb.receiveReplyFor(JdbCommand.cont);
102 
103         reply = jdb.receiveReplyFor(JdbCommand.where);
104         grep = new Paragrep(reply);
105 
106         for (int i = 0; i < FRAMES.length; i++) {
107             v = new Vector();
108             v.add(FRAMES[i][0]);
109             v.add(FRAMES[i][1]);
110             count = grep.find(v);
111             if (count != 1) {
112                 failure("Unexpected number or location of the stack frame: " + FRAMES[i][0] +
113                     "\n\texpected value : 1, got one: " + count);
114             }
115         }
116 
117         jdb.contToExit(1);
118     }
119 }
120