test/jdk/sun/tools/jmap/BasicJMapTest.java
author iklam
Wed, 13 Nov 2019 19:55:11 -0800
changeset 59072 b987ea528c21
parent 53858 e7cf035682e3
permissions -rw-r--r--
8234133: VM build broken due to memory/archiveUtils.inline.hpp Reviewed-by: dholmes
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
/*
53858
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
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
51840
dc15e45122b2 8210894: remove jdk/testlibrary/Asserts
iignatyev
parents: 51687
diff changeset
    24
import static jdk.test.lib.Asserts.assertTrue;
dc15e45122b2 8210894: remove jdk/testlibrary/Asserts
iignatyev
parents: 51687
diff changeset
    25
import static jdk.test.lib.Asserts.fail;
30659
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
51687
1e39953aaed8 8182404: remove jdk.testlibrary.JDKToolFinder and JDKToolLauncher
iignatyev
parents: 51675
diff changeset
    30
import jdk.test.lib.JDKToolLauncher;
30659
f7d610c0c95d 8059047: Extract parser/validator from jhat for use in tests
ykantser
parents: 27189
diff changeset
    31
import jdk.test.lib.hprof.HprofParser;
51675
b487c1e914d0 8210112: remove jdk.testlibrary.ProcessTools
iignatyev
parents: 47216
diff changeset
    32
import jdk.test.lib.process.OutputAnalyzer;
b487c1e914d0 8210112: remove jdk.testlibrary.ProcessTools
iignatyev
parents: 47216
diff changeset
    33
import jdk.test.lib.process.ProcessTools;
22270
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
40686
1b855fa5c9c5 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 38360
diff changeset
    39
 * @library /test/lib
30659
f7d610c0c95d 8059047: Extract parser/validator from jhat for use in tests
ykantser
parents: 27189
diff changeset
    40
 * @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
    41
 * @build jdk.test.lib.hprof.model.*
30659
f7d610c0c95d 8059047: Extract parser/validator from jhat for use in tests
ykantser
parents: 27189
diff changeset
    42
 * @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
    43
 * @build jdk.test.lib.hprof.util.*
30815
4af0e1f6b832 8081292: sun/tools/jmap/BasicJMapTest.java timed out
sla
parents: 30669
diff changeset
    44
 * @run main/timeout=240 BasicJMapTest
22270
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
    45
 */
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
    46
public class BasicJMapTest {
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 ProcessBuilder processBuilder = new ProcessBuilder();
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
    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
    51
        testHisto();
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
    52
        testHistoLive();
53858
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
    53
        testHistoAll();
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
    54
        testHistoToFile();
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
    55
        testHistoLiveToFile();
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
    56
        testHistoAllToFile();
38360
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 34327
diff changeset
    57
        testFinalizerInfo();
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 34327
diff changeset
    58
        testClstats();
22270
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
    59
        testDump();
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
    60
        testDumpLive();
53858
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
    61
        testDumpAll();
22270
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
    62
    }
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
    63
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
    64
    private static void testHisto() throws Exception {
53858
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
    65
        OutputAnalyzer output = jmap("-histo:");
22270
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
    66
        output.shouldHaveExitValue(0);
53858
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
    67
        OutputAnalyzer output1 = jmap("-histo");
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
    68
        output1.shouldHaveExitValue(0);
22270
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
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
    71
    private static void testHistoLive() throws Exception {
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
    72
        OutputAnalyzer output = jmap("-histo:live");
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
    73
        output.shouldHaveExitValue(0);
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
    74
    }
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
    75
53858
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
    76
    private static void testHistoAll() throws Exception {
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
    77
        OutputAnalyzer output = jmap("-histo:all");
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
    78
        output.shouldHaveExitValue(0);
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
    79
    }
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
    80
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
    81
    private static void testHistoToFile() throws Exception {
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
    82
        histoToFile(false);
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
    83
    }
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
    84
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
    85
    private static void testHistoLiveToFile() throws Exception {
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
    86
        histoToFile(true);
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
    87
    }
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
    88
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
    89
    private static void testHistoAllToFile() throws Exception {
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
    90
        boolean explicitAll = true;
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
    91
        histoToFile(false, explicitAll);
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
    92
    }
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
    93
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
    94
    private static void histoToFile(boolean live) throws Exception {
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
    95
        boolean explicitAll = false;
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
    96
        histoToFile(live, explicitAll);
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
    97
    }
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
    98
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
    99
    private static void histoToFile(boolean live, boolean explicitAll) throws Exception {
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
   100
        if (live == true && explicitAll == true) {
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
   101
            fail("Illegal argument setting for jmap -histo");
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
   102
        }
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
   103
        File file = new File("jmap.histo.file" + System.currentTimeMillis() + ".histo");
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
   104
        if (file.exists()) {
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
   105
            file.delete();
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
   106
        }
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
   107
        OutputAnalyzer output;
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
   108
        if (live) {
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
   109
            output = jmap("-histo:live,file=" + file.getName());
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
   110
        } else if (explicitAll == true) {
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
   111
            output = jmap("-histo:all,file=" + file.getName());
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
   112
        } else {
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
   113
            output = jmap("-histo:file=" + file.getName());
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
   114
        }
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
   115
        output.shouldHaveExitValue(0);
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
   116
        output.shouldContain("Heap inspection file created");
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
   117
        file.delete();
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
   118
    }
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
   119
38360
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 34327
diff changeset
   120
    private static void testFinalizerInfo() throws Exception {
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 34327
diff changeset
   121
        OutputAnalyzer output = jmap("-finalizerinfo");
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 34327
diff changeset
   122
        output.shouldHaveExitValue(0);
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 34327
diff changeset
   123
    }
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 34327
diff changeset
   124
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 34327
diff changeset
   125
    private static void testClstats() throws Exception {
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 34327
diff changeset
   126
        OutputAnalyzer output = jmap("-clstats");
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 34327
diff changeset
   127
        output.shouldHaveExitValue(0);
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 34327
diff changeset
   128
    }
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 34327
diff changeset
   129
22270
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
   130
    private static void testDump() throws Exception {
30659
f7d610c0c95d 8059047: Extract parser/validator from jhat for use in tests
ykantser
parents: 27189
diff changeset
   131
        dump(false);
22270
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
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
   134
    private static void testDumpLive() throws Exception {
30659
f7d610c0c95d 8059047: Extract parser/validator from jhat for use in tests
ykantser
parents: 27189
diff changeset
   135
        dump(true);
f7d610c0c95d 8059047: Extract parser/validator from jhat for use in tests
ykantser
parents: 27189
diff changeset
   136
    }
f7d610c0c95d 8059047: Extract parser/validator from jhat for use in tests
ykantser
parents: 27189
diff changeset
   137
53858
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
   138
    private static void testDumpAll() throws Exception {
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
   139
        boolean explicitAll = true;
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
   140
        dump(false, explicitAll);
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
   141
    }
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
   142
30659
f7d610c0c95d 8059047: Extract parser/validator from jhat for use in tests
ykantser
parents: 27189
diff changeset
   143
    private static void dump(boolean live) throws Exception {
53858
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
   144
        boolean explicitAll = false;
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
   145
        dump(live, explicitAll);
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
   146
    }
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
   147
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
   148
    private static void dump(boolean live, boolean explicitAll) throws Exception {
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
   149
        if (live == true && explicitAll == true) {
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
   150
          fail("Illegal argument setting for jmap -dump");
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
   151
        }
30659
f7d610c0c95d 8059047: Extract parser/validator from jhat for use in tests
ykantser
parents: 27189
diff changeset
   152
        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
   153
        if (dump.exists()) {
f7d610c0c95d 8059047: Extract parser/validator from jhat for use in tests
ykantser
parents: 27189
diff changeset
   154
            dump.delete();
f7d610c0c95d 8059047: Extract parser/validator from jhat for use in tests
ykantser
parents: 27189
diff changeset
   155
        }
f7d610c0c95d 8059047: Extract parser/validator from jhat for use in tests
ykantser
parents: 27189
diff changeset
   156
        OutputAnalyzer output;
f7d610c0c95d 8059047: Extract parser/validator from jhat for use in tests
ykantser
parents: 27189
diff changeset
   157
        if (live) {
f7d610c0c95d 8059047: Extract parser/validator from jhat for use in tests
ykantser
parents: 27189
diff changeset
   158
            output = jmap("-dump:live,format=b,file=" + dump.getName());
53858
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
   159
        } else if (explicitAll == true) {
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
   160
            output = jmap("-dump:all,format=b,file=" + dump.getName());
30659
f7d610c0c95d 8059047: Extract parser/validator from jhat for use in tests
ykantser
parents: 27189
diff changeset
   161
        } else {
f7d610c0c95d 8059047: Extract parser/validator from jhat for use in tests
ykantser
parents: 27189
diff changeset
   162
            output = jmap("-dump:format=b,file=" + dump.getName());
f7d610c0c95d 8059047: Extract parser/validator from jhat for use in tests
ykantser
parents: 27189
diff changeset
   163
        }
22270
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
   164
        output.shouldHaveExitValue(0);
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
   165
        output.shouldContain("Heap dump file created");
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
   166
        verifyDumpFile(dump);
30659
f7d610c0c95d 8059047: Extract parser/validator from jhat for use in tests
ykantser
parents: 27189
diff changeset
   167
        dump.delete();
22270
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
   168
    }
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
   169
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
   170
    private static void verifyDumpFile(File dump) {
30659
f7d610c0c95d 8059047: Extract parser/validator from jhat for use in tests
ykantser
parents: 27189
diff changeset
   171
        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
   172
        try {
f7d610c0c95d 8059047: Extract parser/validator from jhat for use in tests
ykantser
parents: 27189
diff changeset
   173
            HprofParser.parse(dump);
f7d610c0c95d 8059047: Extract parser/validator from jhat for use in tests
ykantser
parents: 27189
diff changeset
   174
        } catch (Exception e) {
f7d610c0c95d 8059047: Extract parser/validator from jhat for use in tests
ykantser
parents: 27189
diff changeset
   175
            e.printStackTrace();
f7d610c0c95d 8059047: Extract parser/validator from jhat for use in tests
ykantser
parents: 27189
diff changeset
   176
            fail("Could not parse dump file " + dump.getAbsolutePath());
f7d610c0c95d 8059047: Extract parser/validator from jhat for use in tests
ykantser
parents: 27189
diff changeset
   177
        }
22270
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
   178
    }
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
   179
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
   180
    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
   181
        JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jmap");
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
   182
        if (toolArgs != null) {
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
   183
            for (String toolArg : toolArgs) {
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
   184
                launcher.addToolArg(toolArg);
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
   185
            }
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
   186
        }
34327
50693d25f4a7 8139430: Refactor test library to decrease module dependencies of tests
shurailine
parents: 34324
diff changeset
   187
        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
   188
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
   189
        processBuilder.command(launcher.getCommand());
53858
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 51840
diff changeset
   190
        System.out.println(Arrays.toString(processBuilder.command().toArray()));
27189
b90845965ee9 8056143: interrupted java/lang/management/MemoryMXBean/LowMemoryTest.java leaves running process
jbachorik
parents: 24366
diff changeset
   191
        OutputAnalyzer output = ProcessTools.executeProcess(processBuilder);
22270
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
   192
        System.out.println(output.getOutput());
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
   193
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
   194
        return output;
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
   195
    }
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
   196
e4255239ce3a 6380601: MISC_REGRESSION tests need to be more resilient to ps cmd problems
ykantser
parents:
diff changeset
   197
}