Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/com/sun/jdi/DoubleAgentTest.java
38855 views
1
/*
2
* Copyright (c) 2005, 2013, 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
/* @test
25
* @bug 6354345
26
* @summary Check that a double agent request fails
27
*
28
* @build VMConnection DoubleAgentTest Exit0
29
* @run main DoubleAgentTest
30
*
31
*/
32
import java.io.InputStream;
33
import java.io.IOException;
34
import java.io.File;
35
import java.net.ServerSocket;
36
import java.net.Socket;
37
38
public class DoubleAgentTest {
39
40
static Object locker = new Object();
41
static String outputText = "";
42
43
/*
44
* Helper class to redirect process output/error
45
*/
46
static class IOHandler implements Runnable {
47
InputStream in;
48
49
IOHandler(InputStream in) {
50
this.in = in;
51
}
52
53
static Thread handle(InputStream in) {
54
IOHandler handler = new IOHandler(in);
55
Thread thr = new Thread(handler);
56
thr.setDaemon(true);
57
thr.start();
58
return thr;
59
}
60
61
public void run() {
62
try {
63
byte b[] = new byte[100];
64
for (;;) {
65
int n = in.read(b, 0, 100);
66
// The first thing that will get read is
67
// Listening for transport dt_socket at address: xxxxx
68
// which shows the debuggee is ready to accept connections.
69
synchronized(locker) {
70
locker.notify();
71
}
72
if (n < 0) {
73
break;
74
}
75
String s = new String(b, 0, n, "UTF-8");
76
System.out.print(s);
77
synchronized(outputText) {
78
outputText += s;
79
}
80
}
81
} catch (IOException ioe) {
82
ioe.printStackTrace();
83
}
84
}
85
86
}
87
88
/*
89
* Launch a server debuggee with the given address
90
*/
91
private static Process launch(String address, String class_name) throws IOException {
92
String exe = System.getProperty("java.home")
93
+ File.separator + "bin" + File.separator + "java";
94
String jdwpOption = "-agentlib:jdwp=transport=dt_socket"
95
+ ",server=y" + ",suspend=y" + ",address=" + address;
96
String cmd = exe + " " + VMConnection.getDebuggeeVMOptions()
97
+ " " + jdwpOption
98
+ " " + jdwpOption
99
+ " " + class_name;
100
101
System.out.println("Starting: " + cmd);
102
103
Process p = Runtime.getRuntime().exec(cmd);
104
105
return p;
106
}
107
108
/*
109
* - pick a TCP port
110
* - Launch a server debuggee that should fail
111
* - verify we saw error
112
*/
113
public static void main(String args[]) throws Exception {
114
// find a free port
115
ServerSocket ss = new ServerSocket(0);
116
int port = ss.getLocalPort();
117
ss.close();
118
119
String address = String.valueOf(port);
120
121
// launch the server debuggee
122
Process process = launch(address, "Exit0");
123
Thread t1 = IOHandler.handle(process.getInputStream());
124
Thread t2 = IOHandler.handle(process.getErrorStream());
125
126
// wait for the debugge to be ready
127
synchronized(locker) {
128
locker.wait();
129
}
130
131
int exitCode = process.waitFor();
132
try {
133
t1.join();
134
t2.join();
135
} catch ( InterruptedException e ) {
136
e.printStackTrace();
137
throw new Exception("Debuggee failed InterruptedException");
138
}
139
140
if ( outputText.contains("capabilities") ) {
141
throw new Exception(
142
"Debuggee failed with ERROR about capabilities: " + outputText);
143
}
144
145
if ( !outputText.contains("ERROR") ) {
146
throw new Exception(
147
"Debuggee does not have ERROR in the output: " + outputText);
148
}
149
150
if ( exitCode == 0 ) {
151
throw new Exception(
152
"Debuggee should have failed with an non-zero exit code");
153
}
154
155
}
156
157
}
158
159