author | alanb |
Sat, 06 Apr 2019 16:36:24 +0100 | |
branch | niosocketimpl-branch |
changeset 57308 | f22d38b23756 |
parent 47216 | 71c04702a3d5 |
child 57340 | 9026cb618cdd |
permissions | -rw-r--r-- |
2 | 1 |
/* |
42449
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
2 |
* Copyright (c) 2006, 2016, 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 |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
29 |
* @summary Configuring unconnected Socket before passing to implAccept |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
30 |
* can cause fd leak |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
31 |
* @requires (os.family != "windows") |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
32 |
* @library /test/lib |
45467
99c87a16a8e4
8181761: add explicit @build actions for jdk.test.lib classes in all :tier2 tests
iignatyev
parents:
42449
diff
changeset
|
33 |
* @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
|
34 |
* jdk.test.lib.Asserts |
99c87a16a8e4
8181761: add explicit @build actions for jdk.test.lib classes in all :tier2 tests
iignatyev
parents:
42449
diff
changeset
|
35 |
* jdk.test.lib.JDKToolFinder |
99c87a16a8e4
8181761: add explicit @build actions for jdk.test.lib classes in all :tier2 tests
iignatyev
parents:
42449
diff
changeset
|
36 |
* jdk.test.lib.JDKToolLauncher |
99c87a16a8e4
8181761: add explicit @build actions for jdk.test.lib classes in all :tier2 tests
iignatyev
parents:
42449
diff
changeset
|
37 |
* jdk.test.lib.Platform |
99c87a16a8e4
8181761: add explicit @build actions for jdk.test.lib classes in all :tier2 tests
iignatyev
parents:
42449
diff
changeset
|
38 |
* jdk.test.lib.process.* |
42449
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
39 |
* AcceptCauseFileDescriptorLeak |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
40 |
* @run main/othervm AcceptCauseFileDescriptorLeak root |
57308
f22d38b23756
Add -Djdk.net.usePlainSocketImpl to important tests
alanb
parents:
47216
diff
changeset
|
41 |
* @run main/othervm -Djdk.net.usePlainSocketImpl=true AcceptCauseFileDescriptorLeak root |
2 | 42 |
*/ |
43 |
||
5159
55d38eeb1e33
6935233: java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java fails with modules build
chegar
parents:
2
diff
changeset
|
44 |
import java.io.IOException; |
55d38eeb1e33
6935233: java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java fails with modules build
chegar
parents:
2
diff
changeset
|
45 |
import java.net.ServerSocket; |
55d38eeb1e33
6935233: java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java fails with modules build
chegar
parents:
2
diff
changeset
|
46 |
import java.net.Socket; |
42449
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
47 |
import java.util.List; |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
48 |
|
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
49 |
import jdk.test.lib.JDKToolFinder; |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
50 |
import jdk.test.lib.process.OutputAnalyzer; |
2 | 51 |
|
52 |
public class AcceptCauseFileDescriptorLeak { |
|
5159
55d38eeb1e33
6935233: java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java fails with modules build
chegar
parents:
2
diff
changeset
|
53 |
private static final int REPS = 2048; |
42449
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
54 |
private static final int THRESHOLD = 1024; |
2 | 55 |
|
56 |
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
|
57 |
if (args.length != 0) { |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
58 |
OutputAnalyzer analyzer = execCmd("ulimit -n -H"); |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
59 |
String output = analyzer.getOutput(); |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
60 |
if (output == null || output.length() == 0) { |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
61 |
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
|
62 |
+ " and its exit code is " + analyzer.getExitValue()); |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
63 |
} else { |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
64 |
output = output.trim(); |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
65 |
// Set max open file descriptors to 1024 |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
66 |
// 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
|
67 |
// otherwise just do test directly |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
68 |
if ("unlimited".equals(output) |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
69 |
|| Integer.valueOf(output) > THRESHOLD) { |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
70 |
analyzer = execCmd("ulimit -n " + THRESHOLD + "; " |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
71 |
+ composeJavaTestStr()); |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
72 |
System.out.println("Output: [" |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
73 |
+ analyzer.getOutput() + "]"); |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
74 |
int rc = analyzer.getExitValue(); |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
75 |
if (rc != 0) { |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
76 |
throw new RuntimeException( |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
77 |
"Unexpected exit code: " + rc); |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
78 |
} |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
79 |
return; |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
80 |
} |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
81 |
} |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
82 |
} |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
83 |
|
2 | 84 |
final ServerSocket ss = new ServerSocket(0) { |
85 |
public Socket accept() throws IOException { |
|
42449
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
86 |
Socket s = new Socket() { |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
87 |
}; |
2 | 88 |
s.setSoTimeout(10000); |
89 |
implAccept(s); |
|
90 |
return s; |
|
91 |
} |
|
92 |
}; |
|
93 |
Thread t = new Thread(new Runnable() { |
|
94 |
public void run() { |
|
95 |
try { |
|
96 |
for (int i = 0; i < REPS; i++) { |
|
97 |
(new Socket("localhost", ss.getLocalPort())).close(); |
|
98 |
} |
|
99 |
} catch (IOException e) { |
|
100 |
e.printStackTrace(); |
|
101 |
} |
|
102 |
} |
|
103 |
}); |
|
104 |
t.start(); |
|
42449
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
105 |
try { |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
106 |
for (int i = 0; i < REPS; i++) { |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
107 |
ss.accept().close(); |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
108 |
} |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
109 |
} finally { |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
110 |
ss.close(); |
2 | 111 |
} |
112 |
t.join(); |
|
113 |
} |
|
42449
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
114 |
|
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
115 |
/** |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
116 |
* Execute command with shell |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
117 |
* |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
118 |
* @param command |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
119 |
* @return OutputAnalyzer |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
120 |
* @throws IOException |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
121 |
*/ |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
122 |
static OutputAnalyzer execCmd(String command) throws IOException { |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
123 |
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
|
124 |
System.out.println("Executing: " + cmd); |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
125 |
ProcessBuilder pb = new ProcessBuilder(cmd); |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
126 |
return new OutputAnalyzer(pb.start()); |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
127 |
} |
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 |
static String composeJavaTestStr() { |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
130 |
return JDKToolFinder.getTestJDKTool("java") + " " |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
131 |
+ AcceptCauseFileDescriptorLeak.class.getName(); |
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
132 |
} |
2 | 133 |
} |
42449
ec908b8eb5cc
8043838: Test java/net/ServerSocket/AcceptCauseFileDescriptorLeak.java failed intermittently in nightly
xiaofeya
parents:
7668
diff
changeset
|
134 |