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/trace/trace001.
|
|
29 |
* VM Testbase keywords: [jpda, jdb]
|
|
30 |
* VM Testbase readme:
|
|
31 |
* DECSRIPTION
|
|
32 |
* A positive test case for the 'trace methods <thread id>' command.
|
|
33 |
* The debuggee program (trace001a.java) creates two of additional
|
|
34 |
* threads with name like "MyThread-<number>" and starts them. The jdb
|
|
35 |
* suspends the debuggee at a moment when the additional threads are
|
|
36 |
* waiting for notification for lock objects and then turns on method
|
|
37 |
* tracing for these threads by checked command. After expected
|
|
38 |
* notification the additional threads invoke checked debuggee's methods.
|
|
39 |
* Thus jdb output must have the trace messages of checked methods'
|
|
40 |
* entrance and exit. The test passes if jdb output has two 'enter' messages
|
|
41 |
* and two 'exit' messages for every checked method.
|
|
42 |
* The test consists of two program:
|
|
43 |
* trace001.java - launches jdb and debuggee, writes commands to jdb, reads the jdb output,
|
|
44 |
* trace001a.java - the debugged application.
|
|
45 |
* COMMENTS
|
|
46 |
*
|
|
47 |
* @library /vmTestbase
|
|
48 |
* /test/lib
|
|
49 |
* @run driver jdk.test.lib.FileInstaller . .
|
|
50 |
* @build nsk.jdb.trace.trace001.trace001
|
|
51 |
* nsk.jdb.trace.trace001.trace001a
|
|
52 |
* @run main/othervm PropertyResolvingWrapper nsk.jdb.trace.trace001.trace001
|
|
53 |
* -arch=${os.family}-${os.simpleArch}
|
|
54 |
* -waittime=5
|
|
55 |
* -debugee.vmkind=java
|
|
56 |
* -transport.address=dynamic
|
|
57 |
* -jdb=${test.jdk}/bin/jdb
|
|
58 |
* -java.options="${test.vm.opts} ${test.java.opts}"
|
|
59 |
* -workdir=.
|
|
60 |
* -debugee.vmkeys="${test.vm.opts} ${test.java.opts}"
|
|
61 |
*/
|
|
62 |
|
|
63 |
package nsk.jdb.trace.trace001;
|
|
64 |
|
|
65 |
import nsk.share.*;
|
|
66 |
import nsk.share.jdb.*;
|
|
67 |
|
|
68 |
import java.io.*;
|
|
69 |
import java.util.*;
|
|
70 |
|
|
71 |
public class trace001 extends JdbTest {
|
|
72 |
|
|
73 |
public static void main (String argv[]) {
|
|
74 |
System.exit(run(argv, System.out) + JCK_STATUS_BASE);
|
|
75 |
}
|
|
76 |
|
|
77 |
public static int run(String argv[], PrintStream out) {
|
|
78 |
debuggeeClass = DEBUGGEE_CLASS;
|
|
79 |
firstBreak = FIRST_BREAK;
|
|
80 |
lastBreak = LAST_BREAK;
|
|
81 |
return new trace001().runTest(argv, out);
|
|
82 |
}
|
|
83 |
|
|
84 |
static final String PACKAGE_NAME = "nsk.jdb.trace.trace001";
|
|
85 |
static final String TEST_CLASS = PACKAGE_NAME + ".trace001";
|
|
86 |
static final String DEBUGGEE_CLASS = TEST_CLASS + "a";
|
|
87 |
static final String FIRST_BREAK = DEBUGGEE_CLASS + ".main";
|
|
88 |
static final String LAST_BREAK = DEBUGGEE_CLASS + ".lastBreak";
|
|
89 |
static final String MYTHREAD = "MyThread";
|
|
90 |
static final String DEBUGGEE_THREAD = PACKAGE_NAME + "." + MYTHREAD;
|
|
91 |
|
|
92 |
static final String[] CHECKED_METHODS = {"func1", "func2", "func3"};
|
|
93 |
|
|
94 |
protected void runCases() {
|
|
95 |
String[] reply;
|
|
96 |
Paragrep grep;
|
|
97 |
int count;
|
|
98 |
Vector v;
|
|
99 |
String found;
|
|
100 |
String[] threads;
|
|
101 |
|
|
102 |
jdb.setBreakpointInMethod(LAST_BREAK);
|
|
103 |
reply = jdb.receiveReplyFor(JdbCommand.cont);
|
|
104 |
|
|
105 |
threads = jdb.getThreadIds(DEBUGGEE_THREAD);
|
|
106 |
|
|
107 |
if (threads.length != 2) {
|
|
108 |
log.complain("jdb should report 2 instance of " + DEBUGGEE_THREAD);
|
|
109 |
log.complain("Found: " + threads.length);
|
|
110 |
success = false;
|
|
111 |
}
|
|
112 |
|
|
113 |
for (int i = 0; i < threads.length; i++) {
|
|
114 |
reply = jdb.receiveReplyFor(JdbCommand.trace + "methods " + threads[i]);
|
|
115 |
}
|
|
116 |
|
|
117 |
jdb.contToExit(CHECKED_METHODS.length*threads.length*2 + 3);
|
|
118 |
|
|
119 |
reply = jdb.getTotalReply();
|
|
120 |
if (!checkTrace(CHECKED_METHODS, reply)) {
|
|
121 |
success = false;
|
|
122 |
}
|
|
123 |
}
|
|
124 |
|
|
125 |
private boolean checkTrace (String[] checkedMethods, String[] reply) {
|
|
126 |
Paragrep grep;
|
|
127 |
String found;
|
|
128 |
int count;
|
|
129 |
Vector v = new Vector();
|
|
130 |
boolean result = true;
|
|
131 |
|
|
132 |
grep = new Paragrep(reply);
|
|
133 |
for (int i = 0; i < checkedMethods.length; i++) {
|
|
134 |
v.removeAllElements();
|
|
135 |
v.add(DEBUGGEE_THREAD + "." + checkedMethods[i]);
|
|
136 |
v.add("Method entered");
|
|
137 |
count = grep.find(v);
|
|
138 |
if (count != 2) {
|
|
139 |
log.complain("Count of method enter is incorrect for the method : " + DEBUGGEE_THREAD + "." + checkedMethods[i]);
|
|
140 |
log.complain("Should be 2 trace messages, found : " + count);
|
|
141 |
result= false;
|
|
142 |
}
|
|
143 |
|
|
144 |
v.removeAllElements();
|
|
145 |
v.add(DEBUGGEE_THREAD + "." + checkedMethods[i]);
|
|
146 |
v.add("Method exited");
|
|
147 |
count = grep.find(v);
|
|
148 |
if (count != 2) {
|
|
149 |
log.complain("Count of method exit is incorrect for the method : " + DEBUGGEE_THREAD + "." + checkedMethods[i]);
|
|
150 |
log.complain("Should be 2 trace messages, found : " + count);
|
|
151 |
result= false;
|
|
152 |
}
|
|
153 |
}
|
|
154 |
return result;
|
|
155 |
}
|
|
156 |
}
|