8059047: Extract parser/validator from jhat for use in tests
Reviewed-by: sla
This commit is contained in:
parent
8abeeabcef
commit
ba963fa58d
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2006, 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -21,22 +21,55 @@
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* @bug 6455258
|
||||
* @summary Sanity test for com.sun.management.HotSpotDiagnosticMXBean.dumpHeap
|
||||
* method
|
||||
*/
|
||||
import static jdk.testlibrary.Asserts.assertTrue;
|
||||
import static jdk.testlibrary.Asserts.fail;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.management.*;
|
||||
import java.util.List;
|
||||
import javax.management.MBeanServer;
|
||||
|
||||
import jdk.test.lib.hprof.HprofParser;
|
||||
import jdk.testlibrary.ProcessTools;
|
||||
|
||||
import com.sun.management.HotSpotDiagnosticMXBean;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 6455258
|
||||
* @summary Sanity test for com.sun.management.HotSpotDiagnosticMXBean.dumpHeap method
|
||||
* @library /lib/testlibrary
|
||||
* @library /../../test/lib/share/classes
|
||||
* @build jdk.testlibrary.*
|
||||
* @build jdk.test.lib.hprof.*
|
||||
* @build jdk.test.lib.hprof.module.*
|
||||
* @build jdk.test.lib.hprof.parser.*
|
||||
* @build jdk.test.lib.hprof.utils.*
|
||||
* @run main DumpHeap
|
||||
*/
|
||||
public class DumpHeap {
|
||||
public static void main(String[] argv) throws Exception {
|
||||
List<HotSpotDiagnosticMXBean> list = ManagementFactory.getPlatformMXBeans(HotSpotDiagnosticMXBean.class);
|
||||
System.out.println("Dumping to file: " + argv[0] + " ....");
|
||||
list.get(0).dumpHeap(argv[0], true);
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
List<HotSpotDiagnosticMXBean> list = ManagementFactory.getPlatformMXBeans(HotSpotDiagnosticMXBean.class);
|
||||
File dump = new File(ProcessTools.getProcessId() + ".hprof");
|
||||
if (dump.exists()) {
|
||||
dump.delete();
|
||||
}
|
||||
System.out.println("Dumping to file: " + dump.getAbsolutePath());
|
||||
list.get(0).dumpHeap(dump.getAbsolutePath(), true);
|
||||
|
||||
verifyDumpFile(dump);
|
||||
|
||||
dump.delete();
|
||||
}
|
||||
|
||||
private static void verifyDumpFile(File dump) {
|
||||
assertTrue(dump.exists() && dump.isFile(), "Could not create dump file");
|
||||
try {
|
||||
HprofParser.parse(dump);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail("Could not parse dump file");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,59 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright (c) 2006, 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
|
||||
|
||||
# @test
|
||||
# @bug 6455258
|
||||
# @summary Sanity test for com.sun.management.HotSpotDiagnosticMXBean.dumpHeap
|
||||
# method
|
||||
#
|
||||
# @build DumpHeap
|
||||
# @run shell DumpHeap.sh
|
||||
|
||||
if [ "${TESTJAVA}" = "" ] ; then
|
||||
echo "--Error: TESTJAVA must be defined as the pathname of a jdk to test."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "${COMPILEJAVA}" = "" ] ; then
|
||||
COMPILEJAVA="${TESTJAVA}"
|
||||
fi
|
||||
|
||||
failed=0
|
||||
|
||||
# we use the pid of this shell process to name the heap dump output file.
|
||||
DUMPFILE="java_pid$$.hprof"
|
||||
|
||||
${TESTJAVA}/bin/java ${TESTVMOPTS} -classpath $TESTCLASSES \
|
||||
DumpHeap ${DUMPFILE} || exit 2
|
||||
|
||||
# check that heap dump is parsable
|
||||
${COMPILEJAVA}/bin/jhat ${TESTTOOLVMOPTS} -parseonly true ${DUMPFILE}
|
||||
if [ $? != 0 ]; then failed=1; fi
|
||||
|
||||
# dump file is large so remove it
|
||||
rm ${DUMPFILE}
|
||||
|
||||
exit $failed
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -21,10 +21,13 @@
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import static jdk.testlibrary.Asserts.assertTrue;
|
||||
import static jdk.testlibrary.Asserts.fail;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static jdk.testlibrary.Asserts.*;
|
||||
import jdk.test.lib.hprof.HprofParser;
|
||||
import jdk.testlibrary.JDKToolLauncher;
|
||||
import jdk.testlibrary.OutputAnalyzer;
|
||||
import jdk.testlibrary.ProcessTools;
|
||||
@ -34,7 +37,12 @@ import jdk.testlibrary.ProcessTools;
|
||||
* @bug 6321286
|
||||
* @summary Unit test for jmap utility
|
||||
* @library /lib/testlibrary
|
||||
* @library /../../test/lib/share/classes
|
||||
* @build jdk.testlibrary.*
|
||||
* @build jdk.test.lib.hprof.*
|
||||
* @build jdk.test.lib.hprof.module.*
|
||||
* @build jdk.test.lib.hprof.parser.*
|
||||
* @build jdk.test.lib.hprof.utils.*
|
||||
* @run main BasicJMapTest
|
||||
*/
|
||||
public class BasicJMapTest {
|
||||
@ -59,24 +67,38 @@ public class BasicJMapTest {
|
||||
}
|
||||
|
||||
private static void testDump() throws Exception {
|
||||
File dump = new File("java_pid$" + ProcessTools.getProcessId() + ".hprof");
|
||||
OutputAnalyzer output = jmap("-dump:format=b,file=" + dump.getName());
|
||||
output.shouldHaveExitValue(0);
|
||||
output.shouldContain("Heap dump file created");
|
||||
verifyDumpFile(dump);
|
||||
dump(false);
|
||||
}
|
||||
|
||||
private static void testDumpLive() throws Exception {
|
||||
File dump = new File("java_pid$" + ProcessTools.getProcessId() + ".hprof");
|
||||
OutputAnalyzer output = jmap("-dump:live,format=b,file=" + dump.getName());
|
||||
dump(true);
|
||||
}
|
||||
|
||||
private static void dump(boolean live) throws Exception {
|
||||
File dump = new File("jmap.dump." + System.currentTimeMillis() + ".hprof");
|
||||
if (dump.exists()) {
|
||||
dump.delete();
|
||||
}
|
||||
OutputAnalyzer output;
|
||||
if (live) {
|
||||
output = jmap("-dump:live,format=b,file=" + dump.getName());
|
||||
} else {
|
||||
output = jmap("-dump:format=b,file=" + dump.getName());
|
||||
}
|
||||
output.shouldHaveExitValue(0);
|
||||
output.shouldContain("Heap dump file created");
|
||||
verifyDumpFile(dump);
|
||||
dump.delete();
|
||||
}
|
||||
|
||||
private static void verifyDumpFile(File dump) {
|
||||
assertTrue(dump.exists() && dump.isFile(), "Could not create dump file");
|
||||
dump.delete();
|
||||
assertTrue(dump.exists() && dump.isFile(), "Could not create dump file " + dump.getAbsolutePath());
|
||||
try {
|
||||
HprofParser.parse(dump);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail("Could not parse dump file " + dump.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
private static OutputAnalyzer jmap(String... toolArgs) throws Exception {
|
||||
|
Loading…
Reference in New Issue
Block a user