author | jbachorik |
Fri, 17 Oct 2014 10:53:30 +0200 | |
changeset 27189 | b90845965ee9 |
parent 24366 | 57c0a8b7a936 |
child 30376 | 2ccf2cf7ea48 |
child 30659 | f7d610c0c95d |
permissions | -rw-r--r-- |
22270
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
1 |
/* |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
2 |
* Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. |
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.io.File; |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
25 |
import java.util.Arrays; |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
26 |
|
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
27 |
import static jdk.testlibrary.Asserts.*; |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
28 |
import jdk.testlibrary.JDKToolLauncher; |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
29 |
import jdk.testlibrary.OutputAnalyzer; |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
30 |
import jdk.testlibrary.ProcessTools; |
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 |
* @bug 6321286 |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
35 |
* @summary Unit test for jmap utility |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
36 |
* @library /lib/testlibrary |
24366
57c0a8b7a936
8034960: Serviceability tests using @library failing with java.lang.NoClassDefFoundError
ykantser
parents:
22270
diff
changeset
|
37 |
* @build jdk.testlibrary.* |
22270
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
38 |
* @run main BasicJMapTest |
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 |
public class BasicJMapTest { |
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 |
private static ProcessBuilder processBuilder = new ProcessBuilder(); |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
43 |
|
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
44 |
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
|
45 |
testHisto(); |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
46 |
testHistoLive(); |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
47 |
testDump(); |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
48 |
testDumpLive(); |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
49 |
} |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
50 |
|
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
51 |
private static void testHisto() throws Exception { |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
52 |
OutputAnalyzer output = jmap("-histo"); |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
53 |
output.shouldHaveExitValue(0); |
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 |
|
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
56 |
private static void testHistoLive() throws Exception { |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
57 |
OutputAnalyzer output = jmap("-histo:live"); |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
58 |
output.shouldHaveExitValue(0); |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
59 |
} |
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 |
private static void testDump() throws Exception { |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
62 |
File dump = new File("java_pid$" + ProcessTools.getProcessId() + ".hprof"); |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
63 |
OutputAnalyzer output = jmap("-dump:format=b,file=" + dump.getName()); |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
64 |
output.shouldHaveExitValue(0); |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
65 |
output.shouldContain("Heap dump file created"); |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
66 |
verifyDumpFile(dump); |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
67 |
} |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
68 |
|
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
69 |
private static void testDumpLive() throws Exception { |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
70 |
File dump = new File("java_pid$" + ProcessTools.getProcessId() + ".hprof"); |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
71 |
OutputAnalyzer output = jmap("-dump:live,format=b,file=" + dump.getName()); |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
72 |
output.shouldHaveExitValue(0); |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
73 |
output.shouldContain("Heap dump file created"); |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
74 |
verifyDumpFile(dump); |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
75 |
} |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
76 |
|
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
77 |
private static void verifyDumpFile(File dump) { |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
78 |
assertTrue(dump.exists() && dump.isFile(), "Could not create dump file"); |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
79 |
dump.delete(); |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
80 |
} |
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 |
private static OutputAnalyzer jmap(String... toolArgs) throws Exception { |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
83 |
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jmap"); |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
84 |
launcher.addVMArg("-XX:+UsePerfData"); |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
85 |
if (toolArgs != null) { |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
86 |
for (String toolArg : toolArgs) { |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
87 |
launcher.addToolArg(toolArg); |
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 |
launcher.addToolArg(Integer.toString(ProcessTools.getProcessId())); |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
91 |
|
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
92 |
processBuilder.command(launcher.getCommand()); |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
93 |
System.out.println(Arrays.toString(processBuilder.command().toArray()).replace(",", "")); |
27189
b90845965ee9
8056143: interrupted java/lang/management/MemoryMXBean/LowMemoryTest.java leaves running process
jbachorik
parents:
24366
diff
changeset
|
94 |
OutputAnalyzer output = ProcessTools.executeProcess(processBuilder); |
22270
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
95 |
System.out.println(output.getOutput()); |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
96 |
|
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
97 |
return output; |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
98 |
} |
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
99 |
|
e4255239ce3a
6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff
changeset
|
100 |
} |