author | dfuchs |
Thu, 28 Nov 2019 12:28:48 +0000 | |
changeset 59305 | 219ec11136d9 |
parent 58313 | 8a2bc12d2a9a |
permissions | -rw-r--r-- |
59305
219ec11136d9
8223196: java/nio/channels/spi/SelectorProvider/inheritedChannel/InheritedChannelTest.java fails on Solaris SPARC
dfuchs
parents:
58313
diff
changeset
|
1 |
|
2 | 2 |
/* |
58313
8a2bc12d2a9a
8231450: Copyright header line omitted from 8231187 changeset
michaelm
parents:
58295
diff
changeset
|
3 |
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved. |
2 | 4 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
5 |
* |
|
6 |
* This code is free software; you can redistribute it and/or modify it |
|
7 |
* under the terms of the GNU General Public License version 2 only, as |
|
8 |
* published by the Free Software Foundation. |
|
9 |
* |
|
10 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
11 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
14 |
* accompanied this code). |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License version |
|
17 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
18 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
19 |
* |
|
5506 | 20 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
21 |
* or visit www.oracle.com if you need additional information or have any |
|
22 |
* questions. |
|
2 | 23 |
*/ |
24 |
||
25 |
/* |
|
26 |
* A Launcher to launch a java process with its standard input, output, |
|
27 |
* and error streams connected to a socket. |
|
28 |
*/ |
|
29 |
import java.io.IOException; |
|
45578
cd8f28842351
8182465: Refactor shell test java/nio/channels/spi/SelectorProvider/inheritedChannel/run_tests.sh to java
amlu
parents:
23041
diff
changeset
|
30 |
import java.net.InetAddress; |
cd8f28842351
8182465: Refactor shell test java/nio/channels/spi/SelectorProvider/inheritedChannel/run_tests.sh to java
amlu
parents:
23041
diff
changeset
|
31 |
import java.net.InetSocketAddress; |
cd8f28842351
8182465: Refactor shell test java/nio/channels/spi/SelectorProvider/inheritedChannel/run_tests.sh to java
amlu
parents:
23041
diff
changeset
|
32 |
import java.nio.channels.DatagramChannel; |
cd8f28842351
8182465: Refactor shell test java/nio/channels/spi/SelectorProvider/inheritedChannel/run_tests.sh to java
amlu
parents:
23041
diff
changeset
|
33 |
import java.nio.channels.ServerSocketChannel; |
cd8f28842351
8182465: Refactor shell test java/nio/channels/spi/SelectorProvider/inheritedChannel/run_tests.sh to java
amlu
parents:
23041
diff
changeset
|
34 |
import java.nio.channels.SocketChannel; |
2 | 35 |
|
36 |
public class Launcher { |
|
37 |
||
38 |
static { |
|
49128
97288886180c
8198834: (ch) Enable java/nio/channels/spi/SelectorProvider/inheritedChannel/InheritedChannelTest.java on linux-x64
bpb
parents:
47216
diff
changeset
|
39 |
System.loadLibrary("InheritedChannel"); |
2 | 40 |
} |
41 |
||
42 |
private static native void launch0(String cmdarray[], int fd) throws IOException; |
|
43 |
||
44 |
private static void launch(String className, String options[], String args[], int fd) throws IOException { |
|
45 |
// java [-options] class [args...] |
|
23041
1aa7ce9cd0f1
8010194: java/nio/channels/spi/SelectorProvider/inheritedChannel/run_tests.sh fails with "Timed out waiting ..." (sol)
alanb
parents:
23010
diff
changeset
|
46 |
int optsLen = (options == null) ? 0 : options.length; |
1aa7ce9cd0f1
8010194: java/nio/channels/spi/SelectorProvider/inheritedChannel/run_tests.sh fails with "Timed out waiting ..." (sol)
alanb
parents:
23010
diff
changeset
|
47 |
int argsLen = (args == null) ? 0 : args.length; |
1aa7ce9cd0f1
8010194: java/nio/channels/spi/SelectorProvider/inheritedChannel/run_tests.sh fails with "Timed out waiting ..." (sol)
alanb
parents:
23010
diff
changeset
|
48 |
int len = 1 + optsLen + 1 + argsLen; |
2 | 49 |
String cmdarray[] = new String[len]; |
50 |
int pos = 0; |
|
23041
1aa7ce9cd0f1
8010194: java/nio/channels/spi/SelectorProvider/inheritedChannel/run_tests.sh fails with "Timed out waiting ..." (sol)
alanb
parents:
23010
diff
changeset
|
51 |
cmdarray[pos++] = Util.javaCommand(); |
1aa7ce9cd0f1
8010194: java/nio/channels/spi/SelectorProvider/inheritedChannel/run_tests.sh fails with "Timed out waiting ..." (sol)
alanb
parents:
23010
diff
changeset
|
52 |
if (options != null) { |
1aa7ce9cd0f1
8010194: java/nio/channels/spi/SelectorProvider/inheritedChannel/run_tests.sh fails with "Timed out waiting ..." (sol)
alanb
parents:
23010
diff
changeset
|
53 |
for (String opt: options) { |
1aa7ce9cd0f1
8010194: java/nio/channels/spi/SelectorProvider/inheritedChannel/run_tests.sh fails with "Timed out waiting ..." (sol)
alanb
parents:
23010
diff
changeset
|
54 |
cmdarray[pos++] = opt; |
1aa7ce9cd0f1
8010194: java/nio/channels/spi/SelectorProvider/inheritedChannel/run_tests.sh fails with "Timed out waiting ..." (sol)
alanb
parents:
23010
diff
changeset
|
55 |
} |
2 | 56 |
} |
57 |
cmdarray[pos++] = className; |
|
23041
1aa7ce9cd0f1
8010194: java/nio/channels/spi/SelectorProvider/inheritedChannel/run_tests.sh fails with "Timed out waiting ..." (sol)
alanb
parents:
23010
diff
changeset
|
58 |
if (args != null) { |
1aa7ce9cd0f1
8010194: java/nio/channels/spi/SelectorProvider/inheritedChannel/run_tests.sh fails with "Timed out waiting ..." (sol)
alanb
parents:
23010
diff
changeset
|
59 |
for (String arg: args) { |
1aa7ce9cd0f1
8010194: java/nio/channels/spi/SelectorProvider/inheritedChannel/run_tests.sh fails with "Timed out waiting ..." (sol)
alanb
parents:
23010
diff
changeset
|
60 |
cmdarray[pos++] = arg; |
1aa7ce9cd0f1
8010194: java/nio/channels/spi/SelectorProvider/inheritedChannel/run_tests.sh fails with "Timed out waiting ..." (sol)
alanb
parents:
23010
diff
changeset
|
61 |
} |
2 | 62 |
} |
63 |
launch0(cmdarray, fd); |
|
64 |
} |
|
65 |
||
52778
dbbf46b13d52
8211842: IPv6_supported wrongly returns false when unix domain socket is bound to fd 0
michaelm
parents:
49128
diff
changeset
|
66 |
|
dbbf46b13d52
8211842: IPv6_supported wrongly returns false when unix domain socket is bound to fd 0
michaelm
parents:
49128
diff
changeset
|
67 |
/** |
dbbf46b13d52
8211842: IPv6_supported wrongly returns false when unix domain socket is bound to fd 0
michaelm
parents:
49128
diff
changeset
|
68 |
* Launch 'java' with specified class using a UnixDomainSocket pair linking calling |
dbbf46b13d52
8211842: IPv6_supported wrongly returns false when unix domain socket is bound to fd 0
michaelm
parents:
49128
diff
changeset
|
69 |
* process to the child VM. UnixDomainSocket is a simplified interface to PF_UNIX sockets |
dbbf46b13d52
8211842: IPv6_supported wrongly returns false when unix domain socket is bound to fd 0
michaelm
parents:
49128
diff
changeset
|
70 |
* which supports byte a time reads and writes. |
dbbf46b13d52
8211842: IPv6_supported wrongly returns false when unix domain socket is bound to fd 0
michaelm
parents:
49128
diff
changeset
|
71 |
*/ |
dbbf46b13d52
8211842: IPv6_supported wrongly returns false when unix domain socket is bound to fd 0
michaelm
parents:
49128
diff
changeset
|
72 |
public static UnixDomainSocket launchWithUnixDomainSocket(String className) throws IOException { |
dbbf46b13d52
8211842: IPv6_supported wrongly returns false when unix domain socket is bound to fd 0
michaelm
parents:
49128
diff
changeset
|
73 |
UnixDomainSocket[] socks = UnixDomainSocket.socketpair(); |
dbbf46b13d52
8211842: IPv6_supported wrongly returns false when unix domain socket is bound to fd 0
michaelm
parents:
49128
diff
changeset
|
74 |
launch(className, null, null, socks[0].fd()); |
dbbf46b13d52
8211842: IPv6_supported wrongly returns false when unix domain socket is bound to fd 0
michaelm
parents:
49128
diff
changeset
|
75 |
socks[0].close(); |
dbbf46b13d52
8211842: IPv6_supported wrongly returns false when unix domain socket is bound to fd 0
michaelm
parents:
49128
diff
changeset
|
76 |
return socks[1]; |
dbbf46b13d52
8211842: IPv6_supported wrongly returns false when unix domain socket is bound to fd 0
michaelm
parents:
49128
diff
changeset
|
77 |
} |
dbbf46b13d52
8211842: IPv6_supported wrongly returns false when unix domain socket is bound to fd 0
michaelm
parents:
49128
diff
changeset
|
78 |
|
58295
7973073dd048
8231187: SelectorProvider.inheritedChannel() returns TCP socket channel for Unix domain socket
michaelm
parents:
52778
diff
changeset
|
79 |
/** |
7973073dd048
8231187: SelectorProvider.inheritedChannel() returns TCP socket channel for Unix domain socket
michaelm
parents:
52778
diff
changeset
|
80 |
* Launch specified class with an AF_UNIX socket created externally, and one String arg to child VM |
7973073dd048
8231187: SelectorProvider.inheritedChannel() returns TCP socket channel for Unix domain socket
michaelm
parents:
52778
diff
changeset
|
81 |
*/ |
7973073dd048
8231187: SelectorProvider.inheritedChannel() returns TCP socket channel for Unix domain socket
michaelm
parents:
52778
diff
changeset
|
82 |
public static void launchWithUnixDomainSocket(String className, UnixDomainSocket socket, String arg) throws IOException { |
7973073dd048
8231187: SelectorProvider.inheritedChannel() returns TCP socket channel for Unix domain socket
michaelm
parents:
52778
diff
changeset
|
83 |
String[] args = new String[1]; |
7973073dd048
8231187: SelectorProvider.inheritedChannel() returns TCP socket channel for Unix domain socket
michaelm
parents:
52778
diff
changeset
|
84 |
args[0] = arg; |
7973073dd048
8231187: SelectorProvider.inheritedChannel() returns TCP socket channel for Unix domain socket
michaelm
parents:
52778
diff
changeset
|
85 |
launch(className, null, args, socket.fd()); |
7973073dd048
8231187: SelectorProvider.inheritedChannel() returns TCP socket channel for Unix domain socket
michaelm
parents:
52778
diff
changeset
|
86 |
} |
7973073dd048
8231187: SelectorProvider.inheritedChannel() returns TCP socket channel for Unix domain socket
michaelm
parents:
52778
diff
changeset
|
87 |
|
2 | 88 |
/* |
89 |
* Launch 'java' with specified class with the specified arguments (may be null). |
|
90 |
* The launched process will inherit a connected TCP socket. The remote endpoint |
|
91 |
* will be the SocketChannel returned by this method. |
|
92 |
*/ |
|
93 |
public static SocketChannel launchWithSocketChannel(String className, String options[], String args[]) throws IOException { |
|
94 |
ServerSocketChannel ssc = ServerSocketChannel.open(); |
|
59305
219ec11136d9
8223196: java/nio/channels/spi/SelectorProvider/inheritedChannel/InheritedChannelTest.java fails on Solaris SPARC
dfuchs
parents:
58313
diff
changeset
|
95 |
ssc.socket().bind(new InetSocketAddress(InetAddress.getLocalHost(), 0)); |
2 | 96 |
InetSocketAddress isa = new InetSocketAddress(InetAddress.getLocalHost(), |
97 |
ssc.socket().getLocalPort()); |
|
98 |
SocketChannel sc1 = SocketChannel.open(isa); |
|
99 |
SocketChannel sc2 = ssc.accept(); |
|
100 |
launch(className, options, args, Util.getFD(sc2)); |
|
101 |
sc2.close(); |
|
102 |
ssc.close(); |
|
103 |
return sc1; |
|
104 |
} |
|
105 |
||
106 |
public static SocketChannel launchWithSocketChannel(String className, String args[]) throws IOException { |
|
107 |
return launchWithSocketChannel(className, null, args); |
|
108 |
} |
|
109 |
||
110 |
public static SocketChannel launchWithSocketChannel(String className) throws IOException { |
|
111 |
return launchWithSocketChannel(className, null); |
|
112 |
} |
|
113 |
||
114 |
/* |
|
115 |
* Launch 'java' with specified class with the specified arguments (may be null). |
|
116 |
* The launched process will inherited a TCP listener socket. |
|
117 |
* Once launched this method tries to connect to service. If a connection |
|
118 |
* can be established a SocketChannel, connected to the service, is returned. |
|
119 |
*/ |
|
120 |
public static SocketChannel launchWithServerSocketChannel(String className, String options[], String args[]) |
|
121 |
throws IOException |
|
122 |
{ |
|
123 |
ServerSocketChannel ssc = ServerSocketChannel.open(); |
|
59305
219ec11136d9
8223196: java/nio/channels/spi/SelectorProvider/inheritedChannel/InheritedChannelTest.java fails on Solaris SPARC
dfuchs
parents:
58313
diff
changeset
|
124 |
ssc.socket().bind(new InetSocketAddress(InetAddress.getLocalHost(), 0)); |
2 | 125 |
int port = ssc.socket().getLocalPort(); |
126 |
launch(className, options, args, Util.getFD(ssc)); |
|
127 |
ssc.close(); |
|
128 |
InetSocketAddress isa = new InetSocketAddress(InetAddress.getLocalHost(), port); |
|
129 |
return SocketChannel.open(isa); |
|
130 |
} |
|
131 |
||
132 |
public static SocketChannel launchWithServerSocketChannel(String className, String args[]) throws IOException { |
|
133 |
return launchWithServerSocketChannel(className, null, args); |
|
134 |
} |
|
135 |
||
136 |
public static SocketChannel launchWithServerSocketChannel(String className) throws IOException { |
|
137 |
return launchWithServerSocketChannel(className, null); |
|
138 |
} |
|
139 |
||
140 |
/* |
|
141 |
* Launch 'java' with specified class with the specified arguments (may be null). |
|
142 |
* The launch process will inherited a bound UDP socket. |
|
143 |
* Once launched this method creates a DatagramChannel and "connects |
|
144 |
* it to the service. The created DatagramChannel is then returned. |
|
145 |
* As it is connected any packets sent from the socket will be |
|
146 |
* sent to the service. |
|
147 |
*/ |
|
148 |
public static DatagramChannel launchWithDatagramChannel(String className, String options[], String args[]) |
|
149 |
throws IOException |
|
150 |
{ |
|
59305
219ec11136d9
8223196: java/nio/channels/spi/SelectorProvider/inheritedChannel/InheritedChannelTest.java fails on Solaris SPARC
dfuchs
parents:
58313
diff
changeset
|
151 |
InetAddress address = InetAddress.getLocalHost(); |
219ec11136d9
8223196: java/nio/channels/spi/SelectorProvider/inheritedChannel/InheritedChannelTest.java fails on Solaris SPARC
dfuchs
parents:
58313
diff
changeset
|
152 |
if (address.isLoopbackAddress()) { |
219ec11136d9
8223196: java/nio/channels/spi/SelectorProvider/inheritedChannel/InheritedChannelTest.java fails on Solaris SPARC
dfuchs
parents:
58313
diff
changeset
|
153 |
address = InetAddress.getLoopbackAddress(); |
219ec11136d9
8223196: java/nio/channels/spi/SelectorProvider/inheritedChannel/InheritedChannelTest.java fails on Solaris SPARC
dfuchs
parents:
58313
diff
changeset
|
154 |
} |
2 | 155 |
DatagramChannel dc = DatagramChannel.open(); |
59305
219ec11136d9
8223196: java/nio/channels/spi/SelectorProvider/inheritedChannel/InheritedChannelTest.java fails on Solaris SPARC
dfuchs
parents:
58313
diff
changeset
|
156 |
dc.socket().bind(new InetSocketAddress(address, 0)); |
2 | 157 |
|
158 |
int port = dc.socket().getLocalPort(); |
|
159 |
launch(className, options, args, Util.getFD(dc)); |
|
160 |
dc.close(); |
|
161 |
||
162 |
dc = DatagramChannel.open(); |
|
16480
fcad3b6ec812
7183800: TEST_BUG: Update tests to run on Ubuntu 12.04 (localhost is 127.0.1.1)
alanb
parents:
5506
diff
changeset
|
163 |
InetSocketAddress isa = new InetSocketAddress(address, port); |
2 | 164 |
|
165 |
dc.connect(isa); |
|
166 |
return dc; |
|
167 |
} |
|
168 |
||
169 |
public static DatagramChannel launchWithDatagramChannel(String className, String args[]) throws IOException { |
|
170 |
return launchWithDatagramChannel(className, null, args); |
|
171 |
} |
|
172 |
||
173 |
public static DatagramChannel launchWithDatagramChannel(String className) throws IOException { |
|
174 |
return launchWithDatagramChannel(className, null); |
|
175 |
} |
|
176 |
} |