jdk/test/sun/tools/jmap/BasicJMapTest.java
author dsamersoff
Mon, 09 May 2016 23:41:59 +0300
changeset 38360 fb63be22ffa6
parent 34327 50693d25f4a7
child 40686 1b855fa5c9c5
permissions -rw-r--r--
8155091: Remove SA related functions from tmtools Summary: Remove options that enables support for non-cooperative mode Reviewed-by: alanb, mchung, sla
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
22270
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
     1
/*
38360
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 34327
diff changeset
     2
 * Copyright (c) 2005, 2016, 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
30659
f7d610c0c95d 8059047: Extract parser/validator from jhat for use in tests
ykantser
parents: 27189
diff changeset
    24
import static jdk.testlibrary.Asserts.assertTrue;
f7d610c0c95d 8059047: Extract parser/validator from jhat for use in tests
ykantser
parents: 27189
diff changeset
    25
import static jdk.testlibrary.Asserts.fail;
f7d610c0c95d 8059047: Extract parser/validator from jhat for use in tests
ykantser
parents: 27189
diff changeset
    26
22270
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
    27
import java.io.File;
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
    28
import java.util.Arrays;
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
    29
30659
f7d610c0c95d 8059047: Extract parser/validator from jhat for use in tests
ykantser
parents: 27189
diff changeset
    30
import jdk.test.lib.hprof.HprofParser;
22270
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
    31
import jdk.testlibrary.JDKToolLauncher;
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
    32
import jdk.testlibrary.OutputAnalyzer;
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
    33
import jdk.testlibrary.ProcessTools;
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
    34
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
    35
/*
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
    36
 * @test
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
    37
 * @summary Unit test for jmap utility
32018
91c91b3d50a0 8132094: Mark intermittently failuring core-svc tests
ykantser
parents: 31909
diff changeset
    38
 * @key intermittent
22270
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
    39
 * @library /lib/testlibrary
33832
7dde7a271492 8140189: [TESTBUG] Get rid of "@library /../../test/lib" in jtreg tests
cjplummer
parents: 32018
diff changeset
    40
 * @library /test/lib/share/classes
24366
57c0a8b7a936 8034960: Serviceability tests using @library failing with java.lang.NoClassDefFoundError
ykantser
parents: 22270
diff changeset
    41
 * @build jdk.testlibrary.*
30659
f7d610c0c95d 8059047: Extract parser/validator from jhat for use in tests
ykantser
parents: 27189
diff changeset
    42
 * @build jdk.test.lib.hprof.*
34324
19a97dc4cb26 8143583: Several tests don't work with latest jtreg due to non-existing files in @build
amlu
parents: 33832
diff changeset
    43
 * @build jdk.test.lib.hprof.model.*
30659
f7d610c0c95d 8059047: Extract parser/validator from jhat for use in tests
ykantser
parents: 27189
diff changeset
    44
 * @build jdk.test.lib.hprof.parser.*
34324
19a97dc4cb26 8143583: Several tests don't work with latest jtreg due to non-existing files in @build
amlu
parents: 33832
diff changeset
    45
 * @build jdk.test.lib.hprof.util.*
30815
4af0e1f6b832 8081292: sun/tools/jmap/BasicJMapTest.java timed out
sla
parents: 30669
diff changeset
    46
 * @run main/timeout=240 BasicJMapTest
22270
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
public class BasicJMapTest {
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
    private static ProcessBuilder processBuilder = new ProcessBuilder();
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
    51
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
    52
    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
    53
        testHisto();
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
    54
        testHistoLive();
38360
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 34327
diff changeset
    55
        testFinalizerInfo();
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 34327
diff changeset
    56
        testClstats();
22270
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
    57
        testDump();
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
    58
        testDumpLive();
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 testHisto() throws Exception {
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
    62
        OutputAnalyzer output = jmap("-histo");
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
    63
        output.shouldHaveExitValue(0);
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
    64
    }
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
    65
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
    66
    private static void testHistoLive() throws Exception {
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
    67
        OutputAnalyzer output = jmap("-histo:live");
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
    68
        output.shouldHaveExitValue(0);
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
    69
    }
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
    70
38360
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 34327
diff changeset
    71
    private static void testFinalizerInfo() throws Exception {
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 34327
diff changeset
    72
        OutputAnalyzer output = jmap("-finalizerinfo");
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 34327
diff changeset
    73
        output.shouldHaveExitValue(0);
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 34327
diff changeset
    74
    }
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 34327
diff changeset
    75
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 34327
diff changeset
    76
    private static void testClstats() throws Exception {
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 34327
diff changeset
    77
        OutputAnalyzer output = jmap("-clstats");
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 34327
diff changeset
    78
        output.shouldHaveExitValue(0);
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 34327
diff changeset
    79
    }
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 34327
diff changeset
    80
22270
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
    81
    private static void testDump() throws Exception {
30659
f7d610c0c95d 8059047: Extract parser/validator from jhat for use in tests
ykantser
parents: 27189
diff changeset
    82
        dump(false);
22270
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
    83
    }
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
    84
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
    85
    private static void testDumpLive() throws Exception {
30659
f7d610c0c95d 8059047: Extract parser/validator from jhat for use in tests
ykantser
parents: 27189
diff changeset
    86
        dump(true);
f7d610c0c95d 8059047: Extract parser/validator from jhat for use in tests
ykantser
parents: 27189
diff changeset
    87
    }
f7d610c0c95d 8059047: Extract parser/validator from jhat for use in tests
ykantser
parents: 27189
diff changeset
    88
f7d610c0c95d 8059047: Extract parser/validator from jhat for use in tests
ykantser
parents: 27189
diff changeset
    89
    private static void dump(boolean live) throws Exception {
f7d610c0c95d 8059047: Extract parser/validator from jhat for use in tests
ykantser
parents: 27189
diff changeset
    90
        File dump = new File("jmap.dump." + System.currentTimeMillis() + ".hprof");
f7d610c0c95d 8059047: Extract parser/validator from jhat for use in tests
ykantser
parents: 27189
diff changeset
    91
        if (dump.exists()) {
f7d610c0c95d 8059047: Extract parser/validator from jhat for use in tests
ykantser
parents: 27189
diff changeset
    92
            dump.delete();
f7d610c0c95d 8059047: Extract parser/validator from jhat for use in tests
ykantser
parents: 27189
diff changeset
    93
        }
f7d610c0c95d 8059047: Extract parser/validator from jhat for use in tests
ykantser
parents: 27189
diff changeset
    94
        OutputAnalyzer output;
f7d610c0c95d 8059047: Extract parser/validator from jhat for use in tests
ykantser
parents: 27189
diff changeset
    95
        if (live) {
f7d610c0c95d 8059047: Extract parser/validator from jhat for use in tests
ykantser
parents: 27189
diff changeset
    96
            output = jmap("-dump:live,format=b,file=" + dump.getName());
f7d610c0c95d 8059047: Extract parser/validator from jhat for use in tests
ykantser
parents: 27189
diff changeset
    97
        } else {
f7d610c0c95d 8059047: Extract parser/validator from jhat for use in tests
ykantser
parents: 27189
diff changeset
    98
            output = jmap("-dump:format=b,file=" + dump.getName());
f7d610c0c95d 8059047: Extract parser/validator from jhat for use in tests
ykantser
parents: 27189
diff changeset
    99
        }
22270
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
   100
        output.shouldHaveExitValue(0);
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
   101
        output.shouldContain("Heap dump file created");
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
   102
        verifyDumpFile(dump);
30659
f7d610c0c95d 8059047: Extract parser/validator from jhat for use in tests
ykantser
parents: 27189
diff changeset
   103
        dump.delete();
22270
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
   104
    }
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
   105
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
   106
    private static void verifyDumpFile(File dump) {
30659
f7d610c0c95d 8059047: Extract parser/validator from jhat for use in tests
ykantser
parents: 27189
diff changeset
   107
        assertTrue(dump.exists() && dump.isFile(), "Could not create dump file " + dump.getAbsolutePath());
f7d610c0c95d 8059047: Extract parser/validator from jhat for use in tests
ykantser
parents: 27189
diff changeset
   108
        try {
f7d610c0c95d 8059047: Extract parser/validator from jhat for use in tests
ykantser
parents: 27189
diff changeset
   109
            HprofParser.parse(dump);
f7d610c0c95d 8059047: Extract parser/validator from jhat for use in tests
ykantser
parents: 27189
diff changeset
   110
        } catch (Exception e) {
f7d610c0c95d 8059047: Extract parser/validator from jhat for use in tests
ykantser
parents: 27189
diff changeset
   111
            e.printStackTrace();
f7d610c0c95d 8059047: Extract parser/validator from jhat for use in tests
ykantser
parents: 27189
diff changeset
   112
            fail("Could not parse dump file " + dump.getAbsolutePath());
f7d610c0c95d 8059047: Extract parser/validator from jhat for use in tests
ykantser
parents: 27189
diff changeset
   113
        }
22270
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
   114
    }
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
   115
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
   116
    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
   117
        JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jmap");
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
   118
        if (toolArgs != null) {
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
   119
            for (String toolArg : toolArgs) {
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
   120
                launcher.addToolArg(toolArg);
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
   121
            }
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
   122
        }
34327
50693d25f4a7 8139430: Refactor test library to decrease module dependencies of tests
shurailine
parents: 34324
diff changeset
   123
        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
   124
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
   125
        processBuilder.command(launcher.getCommand());
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
   126
        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
   127
        OutputAnalyzer output = ProcessTools.executeProcess(processBuilder);
22270
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
   128
        System.out.println(output.getOutput());
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
   129
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
   130
        return output;
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
   131
    }
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
   132
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
   133
}