author | chegar |
Thu, 17 Oct 2019 20:54:25 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58679 | 9c3209ff7550 |
parent 58678 | 9cf78a70fa4f |
parent 57564 | 0a8436eda2fa |
permissions | -rw-r--r-- |
22270
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
1 |
/* |
55758
bbe9c361a477
8227868: jinfo and jstack can fail converting UTF8 output to strings
rschmelter
parents:
51687
diff
changeset
|
2 |
* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved. |
22270
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
4 |
* |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
8 |
* |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
13 |
* accompanied this code). |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
14 |
* |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
18 |
* |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
21 |
* questions. |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
22 |
*/ |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
23 |
|
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
24 |
import java.util.Arrays; |
57564
0a8436eda2fa
8228589: BasicJStackTest.java and JcmdOutputEncodingTest.java failing after JDK-8227868
rschmelter
parents:
55758
diff
changeset
|
25 |
import java.nio.charset.Charset; |
0a8436eda2fa
8228589: BasicJStackTest.java and JcmdOutputEncodingTest.java failing after JDK-8227868
rschmelter
parents:
55758
diff
changeset
|
26 |
import java.nio.charset.StandardCharsets; |
22270
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
27 |
|
51675 | 28 |
import jdk.test.lib.process.OutputAnalyzer; |
29 |
import jdk.test.lib.process.ProcessTools; |
|
51687
1e39953aaed8
8182404: remove jdk.testlibrary.JDKToolFinder and JDKToolLauncher
iignatyev
parents:
51675
diff
changeset
|
30 |
import jdk.test.lib.JDKToolLauncher; |
22270
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
31 |
|
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
32 |
/* |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
33 |
* @test |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
34 |
* @summary Unit test for jstack utility |
51675 | 35 |
* @library /test/lib |
22270
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
36 |
* @run main BasicJStackTest |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
37 |
*/ |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
38 |
public class BasicJStackTest { |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
39 |
|
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
40 |
private static ProcessBuilder processBuilder = new ProcessBuilder(); |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
41 |
|
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
42 |
public static void main(String[] args) throws Exception { |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
43 |
testJstackNoArgs(); |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
44 |
testJstack_l(); |
57564
0a8436eda2fa
8228589: BasicJStackTest.java and JcmdOutputEncodingTest.java failing after JDK-8227868
rschmelter
parents:
55758
diff
changeset
|
45 |
testJstackUTF8Encoding(); |
22270
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
46 |
} |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
47 |
|
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
48 |
private static void testJstackNoArgs() throws Exception { |
57564
0a8436eda2fa
8228589: BasicJStackTest.java and JcmdOutputEncodingTest.java failing after JDK-8227868
rschmelter
parents:
55758
diff
changeset
|
49 |
String marker = "testJstackNoArgs"; |
0a8436eda2fa
8228589: BasicJStackTest.java and JcmdOutputEncodingTest.java failing after JDK-8227868
rschmelter
parents:
55758
diff
changeset
|
50 |
OutputAnalyzer output = jstack(marker); |
22270
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
51 |
output.shouldHaveExitValue(0); |
57564
0a8436eda2fa
8228589: BasicJStackTest.java and JcmdOutputEncodingTest.java failing after JDK-8227868
rschmelter
parents:
55758
diff
changeset
|
52 |
output.shouldContain(marker); |
22270
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
53 |
} |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
54 |
|
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
55 |
private static void testJstack_l() throws Exception { |
57564
0a8436eda2fa
8228589: BasicJStackTest.java and JcmdOutputEncodingTest.java failing after JDK-8227868
rschmelter
parents:
55758
diff
changeset
|
56 |
String marker = "testJstack_l"; |
0a8436eda2fa
8228589: BasicJStackTest.java and JcmdOutputEncodingTest.java failing after JDK-8227868
rschmelter
parents:
55758
diff
changeset
|
57 |
OutputAnalyzer output = jstack(marker, "-l"); |
22270
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
58 |
output.shouldHaveExitValue(0); |
57564
0a8436eda2fa
8228589: BasicJStackTest.java and JcmdOutputEncodingTest.java failing after JDK-8227868
rschmelter
parents:
55758
diff
changeset
|
59 |
output.shouldContain(marker); |
22270
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
60 |
} |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
61 |
|
57564
0a8436eda2fa
8228589: BasicJStackTest.java and JcmdOutputEncodingTest.java failing after JDK-8227868
rschmelter
parents:
55758
diff
changeset
|
62 |
private static void testJstackUTF8Encoding() throws Exception { |
0a8436eda2fa
8228589: BasicJStackTest.java and JcmdOutputEncodingTest.java failing after JDK-8227868
rschmelter
parents:
55758
diff
changeset
|
63 |
String marker = "markerName" + "\u00e4\u0bb5".repeat(60); |
0a8436eda2fa
8228589: BasicJStackTest.java and JcmdOutputEncodingTest.java failing after JDK-8227868
rschmelter
parents:
55758
diff
changeset
|
64 |
OutputAnalyzer output = jstack(marker); |
0a8436eda2fa
8228589: BasicJStackTest.java and JcmdOutputEncodingTest.java failing after JDK-8227868
rschmelter
parents:
55758
diff
changeset
|
65 |
output.shouldHaveExitValue(0); |
0a8436eda2fa
8228589: BasicJStackTest.java and JcmdOutputEncodingTest.java failing after JDK-8227868
rschmelter
parents:
55758
diff
changeset
|
66 |
output.shouldContain(marker); |
0a8436eda2fa
8228589: BasicJStackTest.java and JcmdOutputEncodingTest.java failing after JDK-8227868
rschmelter
parents:
55758
diff
changeset
|
67 |
} |
0a8436eda2fa
8228589: BasicJStackTest.java and JcmdOutputEncodingTest.java failing after JDK-8227868
rschmelter
parents:
55758
diff
changeset
|
68 |
|
0a8436eda2fa
8228589: BasicJStackTest.java and JcmdOutputEncodingTest.java failing after JDK-8227868
rschmelter
parents:
55758
diff
changeset
|
69 |
private static OutputAnalyzer jstack(String marker, String... toolArgs) throws Exception { |
0a8436eda2fa
8228589: BasicJStackTest.java and JcmdOutputEncodingTest.java failing after JDK-8227868
rschmelter
parents:
55758
diff
changeset
|
70 |
Charset cs = StandardCharsets.UTF_8; |
0a8436eda2fa
8228589: BasicJStackTest.java and JcmdOutputEncodingTest.java failing after JDK-8227868
rschmelter
parents:
55758
diff
changeset
|
71 |
Thread.currentThread().setName(marker); |
22270
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
72 |
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jstack"); |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
73 |
launcher.addVMArg("-XX:+UsePerfData"); |
57564
0a8436eda2fa
8228589: BasicJStackTest.java and JcmdOutputEncodingTest.java failing after JDK-8227868
rschmelter
parents:
55758
diff
changeset
|
74 |
launcher.addVMArg("-Dfile.encoding=" + cs); |
22270
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
75 |
if (toolArgs != null) { |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
76 |
for (String toolArg : toolArgs) { |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
77 |
launcher.addToolArg(toolArg); |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
78 |
} |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
79 |
} |
34327
50693d25f4a7
8139430: Refactor test library to decrease module dependencies of tests
shurailine
parents:
30376
diff
changeset
|
80 |
launcher.addToolArg(Long.toString(ProcessTools.getProcessId())); |
22270
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
81 |
|
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
82 |
processBuilder.command(launcher.getCommand()); |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
83 |
System.out.println(Arrays.toString(processBuilder.command().toArray()).replace(",", "")); |
57564
0a8436eda2fa
8228589: BasicJStackTest.java and JcmdOutputEncodingTest.java failing after JDK-8227868
rschmelter
parents:
55758
diff
changeset
|
84 |
OutputAnalyzer output = ProcessTools.executeProcess(processBuilder, null, cs); |
22270
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
85 |
System.out.println(output.getOutput()); |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
86 |
|
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
87 |
return output; |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
88 |
} |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
89 |
|
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
90 |
} |