author | jboes |
Fri, 08 Nov 2019 11:15:16 +0000 | |
changeset 59029 | 3786a0962570 |
parent 57686 | 70f5cbb711a9 |
child 58679 | 9c3209ff7550 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
54841
43439afaab4a
8223638: Replace wildcard address with loopback or local host in tests - part 6
aefimov
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2006, 2019, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 22 |
*/ |
23 |
||
24 |
/* |
|
5159
55d38eeb1e33
6935233: java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java fails with modules build
chegar
parents:
2
diff
changeset
|
25 |
* author Edward Wang |
42449
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
26 |
* |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
27 |
* @test |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
28 |
* @bug 6368984 |
57686
70f5cbb711a9
8225430: Replace wildcard address with loopback or local host in tests - part 14
aefimov
parents:
55102
diff
changeset
|
29 |
* @key intermittent |
42449
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
30 |
* @summary Configuring unconnected Socket before passing to implAccept |
57686
70f5cbb711a9
8225430: Replace wildcard address with loopback or local host in tests - part 14
aefimov
parents:
55102
diff
changeset
|
31 |
* can cause fd leak. |
70f5cbb711a9
8225430: Replace wildcard address with loopback or local host in tests - part 14
aefimov
parents:
55102
diff
changeset
|
32 |
* This test may fail intermittently if foreign processes will |
70f5cbb711a9
8225430: Replace wildcard address with loopback or local host in tests - part 14
aefimov
parents:
55102
diff
changeset
|
33 |
* try to establish connection to the test server socket. |
42449
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
34 |
* @requires (os.family != "windows") |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
35 |
* @library /test/lib |
45467
99c87a16a8e4
8181761: add explicit @build actions for jdk.test.lib classes in all :tier2 tests
iignatyev
parents:
42449
diff
changeset
|
36 |
* @build jdk.test.lib.Utils |
99c87a16a8e4
8181761: add explicit @build actions for jdk.test.lib classes in all :tier2 tests
iignatyev
parents:
42449
diff
changeset
|
37 |
* jdk.test.lib.Asserts |
99c87a16a8e4
8181761: add explicit @build actions for jdk.test.lib classes in all :tier2 tests
iignatyev
parents:
42449
diff
changeset
|
38 |
* jdk.test.lib.JDKToolFinder |
99c87a16a8e4
8181761: add explicit @build actions for jdk.test.lib classes in all :tier2 tests
iignatyev
parents:
42449
diff
changeset
|
39 |
* jdk.test.lib.JDKToolLauncher |
99c87a16a8e4
8181761: add explicit @build actions for jdk.test.lib classes in all :tier2 tests
iignatyev
parents:
42449
diff
changeset
|
40 |
* jdk.test.lib.Platform |
99c87a16a8e4
8181761: add explicit @build actions for jdk.test.lib classes in all :tier2 tests
iignatyev
parents:
42449
diff
changeset
|
41 |
* jdk.test.lib.process.* |
42449
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
42 |
* AcceptCauseFileDescriptorLeak |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
43 |
* @run main/othervm AcceptCauseFileDescriptorLeak root |
55102 | 44 |
* @run main/othervm -Djdk.net.usePlainSocketImpl AcceptCauseFileDescriptorLeak root |
2 | 45 |
*/ |
46 |
||
5159
55d38eeb1e33
6935233: java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java fails with modules build
chegar
parents:
2
diff
changeset
|
47 |
import java.io.IOException; |
54841
43439afaab4a
8223638: Replace wildcard address with loopback or local host in tests - part 6
aefimov
parents:
47216
diff
changeset
|
48 |
import java.net.InetAddress; |
57686
70f5cbb711a9
8225430: Replace wildcard address with loopback or local host in tests - part 14
aefimov
parents:
55102
diff
changeset
|
49 |
import java.net.InetSocketAddress; |
5159
55d38eeb1e33
6935233: java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java fails with modules build
chegar
parents:
2
diff
changeset
|
50 |
import java.net.ServerSocket; |
55d38eeb1e33
6935233: java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java fails with modules build
chegar
parents:
2
diff
changeset
|
51 |
import java.net.Socket; |
42449
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
52 |
import java.util.List; |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
53 |
|
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
54 |
import jdk.test.lib.JDKToolFinder; |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
55 |
import jdk.test.lib.process.OutputAnalyzer; |
2 | 56 |
|
57 |
public class AcceptCauseFileDescriptorLeak { |
|
5159
55d38eeb1e33
6935233: java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java fails with modules build
chegar
parents:
2
diff
changeset
|
58 |
private static final int REPS = 2048; |
42449
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
59 |
private static final int THRESHOLD = 1024; |
2 | 60 |
|
61 |
public static void main(String[] args) throws Exception { |
|
42449
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
62 |
if (args.length != 0) { |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
63 |
OutputAnalyzer analyzer = execCmd("ulimit -n -H"); |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
64 |
String output = analyzer.getOutput(); |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
65 |
if (output == null || output.length() == 0) { |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
66 |
throw new RuntimeException("\"ulimit -n -H\" output nothing" |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
67 |
+ " and its exit code is " + analyzer.getExitValue()); |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
68 |
} else { |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
69 |
output = output.trim(); |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
70 |
// Set max open file descriptors to 1024 |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
71 |
// if it is unlimited or greater than 1024, |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
72 |
// otherwise just do test directly |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
73 |
if ("unlimited".equals(output) |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
74 |
|| Integer.valueOf(output) > THRESHOLD) { |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
75 |
analyzer = execCmd("ulimit -n " + THRESHOLD + "; " |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
76 |
+ composeJavaTestStr()); |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
77 |
System.out.println("Output: [" |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
78 |
+ analyzer.getOutput() + "]"); |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
79 |
int rc = analyzer.getExitValue(); |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
80 |
if (rc != 0) { |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
81 |
throw new RuntimeException( |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
82 |
"Unexpected exit code: " + rc); |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
83 |
} |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
84 |
return; |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
85 |
} |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
86 |
} |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
87 |
} |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
88 |
|
57686
70f5cbb711a9
8225430: Replace wildcard address with loopback or local host in tests - part 14
aefimov
parents:
55102
diff
changeset
|
89 |
final ServerSocket ss = new ServerSocket() { |
2 | 90 |
public Socket accept() throws IOException { |
42449
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
91 |
Socket s = new Socket() { |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
92 |
}; |
2 | 93 |
s.setSoTimeout(10000); |
94 |
implAccept(s); |
|
95 |
return s; |
|
96 |
} |
|
97 |
}; |
|
57686
70f5cbb711a9
8225430: Replace wildcard address with loopback or local host in tests - part 14
aefimov
parents:
55102
diff
changeset
|
98 |
ss.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0)); |
2 | 99 |
Thread t = new Thread(new Runnable() { |
100 |
public void run() { |
|
57686
70f5cbb711a9
8225430: Replace wildcard address with loopback or local host in tests - part 14
aefimov
parents:
55102
diff
changeset
|
101 |
int repsCompleted = 0; |
2 | 102 |
try { |
57686
70f5cbb711a9
8225430: Replace wildcard address with loopback or local host in tests - part 14
aefimov
parents:
55102
diff
changeset
|
103 |
for (; repsCompleted < REPS; repsCompleted++) { |
54841
43439afaab4a
8223638: Replace wildcard address with loopback or local host in tests - part 6
aefimov
parents:
47216
diff
changeset
|
104 |
(new Socket(InetAddress.getLoopbackAddress(), ss.getLocalPort())).close(); |
2 | 105 |
} |
106 |
} catch (IOException e) { |
|
107 |
e.printStackTrace(); |
|
57686
70f5cbb711a9
8225430: Replace wildcard address with loopback or local host in tests - part 14
aefimov
parents:
55102
diff
changeset
|
108 |
} finally { |
70f5cbb711a9
8225430: Replace wildcard address with loopback or local host in tests - part 14
aefimov
parents:
55102
diff
changeset
|
109 |
System.out.println("Client iterations completed:" + repsCompleted); |
2 | 110 |
} |
111 |
} |
|
112 |
}); |
|
113 |
t.start(); |
|
57686
70f5cbb711a9
8225430: Replace wildcard address with loopback or local host in tests - part 14
aefimov
parents:
55102
diff
changeset
|
114 |
int repsCompleted = 0; |
42449
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
115 |
try { |
57686
70f5cbb711a9
8225430: Replace wildcard address with loopback or local host in tests - part 14
aefimov
parents:
55102
diff
changeset
|
116 |
for (; repsCompleted < REPS; repsCompleted++) { |
42449
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
117 |
ss.accept().close(); |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
118 |
} |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
119 |
} finally { |
57686
70f5cbb711a9
8225430: Replace wildcard address with loopback or local host in tests - part 14
aefimov
parents:
55102
diff
changeset
|
120 |
System.out.println("Server iterations completed:" + repsCompleted); |
42449
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
121 |
ss.close(); |
2 | 122 |
} |
123 |
t.join(); |
|
124 |
} |
|
42449
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
125 |
|
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
126 |
/** |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
127 |
* Execute command with shell |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
128 |
* |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
129 |
* @param command |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
130 |
* @return OutputAnalyzer |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
131 |
* @throws IOException |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
132 |
*/ |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
133 |
static OutputAnalyzer execCmd(String command) throws IOException { |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
134 |
List<String> cmd = List.of("sh", "-c", command); |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
135 |
System.out.println("Executing: " + cmd); |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
136 |
ProcessBuilder pb = new ProcessBuilder(cmd); |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
137 |
return new OutputAnalyzer(pb.start()); |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
138 |
} |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
139 |
|
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
140 |
static String composeJavaTestStr() { |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
141 |
return JDKToolFinder.getTestJDKTool("java") + " " |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
142 |
+ AcceptCauseFileDescriptorLeak.class.getName(); |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
143 |
} |
2 | 144 |
} |
42449
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
145 |