50220
|
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/where006.
|
|
29 |
* VM Testbase keywords: [jpda, jdb]
|
|
30 |
* VM Testbase readme:
|
|
31 |
* DECSRIPTION
|
|
32 |
* A test to exercise the functionality of the 'where <thread_id>'
|
|
33 |
* and the 'where all' commands.
|
|
34 |
* The debugee creates 5 threads that are all suspended on locks
|
|
35 |
* that the main thread posseses. The 'where <thread_id>' command
|
|
36 |
* is used to get stack traces of all 5 suspended threads. The test
|
|
37 |
* passes if contents of the stack trace match to expected output.
|
|
38 |
* COMMENTS
|
|
39 |
* This test functionally equals to nsk/jdb/where/where003 test
|
|
40 |
* and replaces it.
|
|
41 |
*
|
|
42 |
* @library /vmTestbase
|
|
43 |
* /test/lib
|
|
44 |
* @run driver jdk.test.lib.FileInstaller . .
|
|
45 |
* @build nsk.jdb.where.where006.where006
|
|
46 |
* nsk.jdb.where.where006.where006a
|
|
47 |
* @run main/othervm PropertyResolvingWrapper nsk.jdb.where.where006.where006
|
|
48 |
* -arch=${os.family}-${os.simpleArch}
|
|
49 |
* -waittime=5
|
|
50 |
* -debugee.vmkind=java
|
|
51 |
* -transport.address=dynamic
|
|
52 |
* -jdb=${test.jdk}/bin/jdb
|
|
53 |
* -java.options="${test.vm.opts} ${test.java.opts}"
|
|
54 |
* -workdir=.
|
|
55 |
* -debugee.vmkeys="${test.vm.opts} ${test.java.opts}"
|
|
56 |
*/
|
|
57 |
|
|
58 |
package nsk.jdb.where.where006;
|
|
59 |
|
|
60 |
import nsk.share.*;
|
|
61 |
import nsk.share.jdb.*;
|
|
62 |
|
|
63 |
import java.io.*;
|
|
64 |
import java.util.*;
|
|
65 |
|
|
66 |
public class where006 extends JdbTest {
|
|
67 |
|
|
68 |
public static void main (String argv[]) {
|
|
69 |
System.exit(run(argv, System.out) + JCK_STATUS_BASE);
|
|
70 |
}
|
|
71 |
|
|
72 |
public static int run(String argv[], PrintStream out) {
|
|
73 |
debuggeeClass = DEBUGGEE_CLASS;
|
|
74 |
firstBreak = FIRST_BREAK;
|
|
75 |
lastBreak = LAST_BREAK;
|
|
76 |
return new where006().runTest(argv, out);
|
|
77 |
}
|
|
78 |
|
|
79 |
static final String PACKAGE_NAME = "nsk.jdb.where.where006";
|
|
80 |
static final String TEST_CLASS = PACKAGE_NAME + ".where006";
|
|
81 |
static final String DEBUGGEE_CLASS = TEST_CLASS + "a";
|
|
82 |
static final String FIRST_BREAK = DEBUGGEE_CLASS + ".main";
|
|
83 |
static final String LAST_BREAK = DEBUGGEE_CLASS + ".lastBreak";
|
|
84 |
|
|
85 |
static final String[][] FRAMES = new String[][] {
|
|
86 |
{PACKAGE_NAME + ".MyThread.func5", "111"},
|
|
87 |
{PACKAGE_NAME + ".MyThread.func4", "103"},
|
|
88 |
{PACKAGE_NAME + ".MyThread.func3", "99"},
|
|
89 |
{PACKAGE_NAME + ".MyThread.func2", "95"},
|
|
90 |
{PACKAGE_NAME + ".MyThread.func1", "91"},
|
|
91 |
{PACKAGE_NAME + ".MyThread.run", "85"},
|
|
92 |
};
|
|
93 |
protected void runCases() {
|
|
94 |
String[] reply;
|
|
95 |
Paragrep grep;
|
|
96 |
int count;
|
|
97 |
Vector v;
|
|
98 |
String found;
|
|
99 |
|
|
100 |
jdb.setBreakpointInMethod(LAST_BREAK);
|
|
101 |
jdb.receiveReplyFor(JdbCommand.cont);
|
|
102 |
|
|
103 |
String[] threadIds = jdb.getThreadIds(PACKAGE_NAME + ".MyThread");
|
|
104 |
reply = jdb.receiveReplyFor(JdbCommand.where + "all");
|
|
105 |
for (int i = 0; i < where006a.numThreads; i++) {
|
|
106 |
checkFrames(threadIds[i], reply, 5);
|
|
107 |
}
|
|
108 |
|
|
109 |
for (int i = 0; i < where006a.numThreads; i++) {
|
|
110 |
reply = jdb.receiveReplyFor(JdbCommand.where + threadIds[i]);
|
|
111 |
checkFrames(threadIds[i], reply, 1);
|
|
112 |
}
|
|
113 |
|
|
114 |
jdb.contToExit(1);
|
|
115 |
}
|
|
116 |
|
|
117 |
void checkFrames (String threadId, String[] reply, int expectedVal) {
|
|
118 |
Paragrep grep;
|
|
119 |
int count;
|
|
120 |
Vector v;
|
|
121 |
String found;
|
|
122 |
|
|
123 |
grep = new Paragrep(reply);
|
|
124 |
for (int j = 0; j < FRAMES.length; j++) {
|
|
125 |
count = grep.find(FRAMES[j][0]);
|
|
126 |
if (count != expectedVal) {
|
|
127 |
failure("Unexpected number of occurencies of the stack frame: " + FRAMES[j][0] +
|
|
128 |
" for thread " + threadId +
|
|
129 |
"\n\t Expected number of occurence: " + expectedVal +", got : " + count);
|
|
130 |
if (count > 0) {
|
|
131 |
found = grep.findFirst(FRAMES[j][0]);
|
|
132 |
if (found.indexOf(FRAMES[j][1]) < 0) {
|
|
133 |
failure("Unexpected location in the stack frame: " + FRAMES[j][0] +
|
|
134 |
" for thread " + threadId +
|
|
135 |
"\n\t Expected location: " + FRAMES[j][1] + ", got :\n\t" + found);
|
|
136 |
}
|
|
137 |
}
|
|
138 |
}
|
|
139 |
}
|
|
140 |
}
|
|
141 |
}
|