test/jdk/sun/tools/jinfo/JInfoTest.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 44423 jdk/test/sun/tools/jinfo/JInfoTest.java@306c020eb154
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
38956
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
     1
/*
44337
9e4eb1b70d5b 8176471: [TESTBUG] runtime/modules/IgnoreModulePropertiesTest.java fails with OpenJDK: java.lang.RuntimeException: 'java version ' missing from stdout/stderr
hseigel
parents: 40686
diff changeset
     2
 * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
38956
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
     4
 *
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
     7
 * published by the Free Software Foundation.
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
     8
 *
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    13
 * accompanied this code).
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    14
 *
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    18
 *
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    21
 * questions.
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    22
 */
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    23
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    24
import java.util.ArrayList;
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    25
import java.util.Arrays;
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    26
import java.util.List;
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    27
import java.util.regex.Matcher;
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    28
import java.util.regex.Pattern;
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    29
import java.io.IOException;
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    30
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    31
import jdk.test.lib.JDKToolLauncher;
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    32
import jdk.test.lib.process.OutputAnalyzer;
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    33
import jdk.test.lib.process.ProcessTools;
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    34
import jdk.test.lib.apps.LingeredApp;
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    35
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    36
/*
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    37
 * @test
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    38
 * @summary Unit test for jinfo utility
44423
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 44337
diff changeset
    39
 *
40686
1b855fa5c9c5 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 38956
diff changeset
    40
 * @library /test/lib
44423
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 44337
diff changeset
    41
 * @modules java.base/jdk.internal.misc
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 44337
diff changeset
    42
 *          java.management
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 44337
diff changeset
    43
 *          jdk.jcmd
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 44337
diff changeset
    44
 *
38956
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    45
 * @run main JInfoTest
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    46
 */
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    47
public class JInfoTest {
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    48
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    49
    private static ProcessBuilder processBuilder = new ProcessBuilder();
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    50
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    51
    public static void main(String[] args) throws Exception {
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    52
        classNameMatch();
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    53
        setMultipleFlags();
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    54
        setFlag();
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    55
    }
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    56
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    57
    private static void setFlag() throws Exception {
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    58
        System.out.println("#### setFlag ####");
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    59
        LingeredApp app1 = new JInfoTestLingeredApp();
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    60
        LingeredApp app2 = new JInfoTestLingeredApp();
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    61
        try {
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    62
            ArrayList<String> params = new ArrayList<String>();
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    63
            LingeredApp.startApp(params, app1);
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    64
            LingeredApp.startApp(params, app2);
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    65
            OutputAnalyzer output = jinfo("-flag", "MinHeapFreeRatio=1", "JInfoTestLingeredApp");
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    66
            output.shouldHaveExitValue(0);
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    67
            output = jinfo("-flag", "MinHeapFreeRatio", "JInfoTestLingeredApp");
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    68
            output.shouldHaveExitValue(0);
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    69
            documentMatch(output.getStdout(), ".*MinHeapFreeRatio=1.*MinHeapFreeRatio=1.*");
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    70
        } finally {
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    71
            JInfoTestLingeredApp.stopApp(app1);
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    72
            JInfoTestLingeredApp.stopApp(app2);
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    73
        }
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    74
    }
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    75
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    76
    private static void setMultipleFlags() throws Exception {
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    77
        System.out.println("#### setMultipleFlags ####");
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    78
        OutputAnalyzer output = jinfo("-sysprops", "-flag", "MinHeapFreeRatio=1", "-flags", "JInfoTestLingeredApp");
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    79
        output.shouldHaveExitValue(1);
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    80
    }
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    81
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    82
    private static void classNameMatch() throws Exception {
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    83
        System.out.println("#### classNameMatch ####");
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    84
        LingeredApp app1 = new JInfoTestLingeredApp();
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    85
        LingeredApp app2 = new JInfoTestLingeredApp();
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    86
        try {
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    87
            ArrayList<String> params = new ArrayList<String>();
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    88
            LingeredApp.startApp(params, app1);
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    89
            LingeredApp.startApp(params, app2);
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    90
            OutputAnalyzer output = jinfo("JInfoTestLingeredApp");
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    91
            output.shouldHaveExitValue(0);
44337
9e4eb1b70d5b 8176471: [TESTBUG] runtime/modules/IgnoreModulePropertiesTest.java fails with OpenJDK: java.lang.RuntimeException: 'java version ' missing from stdout/stderr
hseigel
parents: 40686
diff changeset
    92
            // "Runtime Environment" written once per proc
9e4eb1b70d5b 8176471: [TESTBUG] runtime/modules/IgnoreModulePropertiesTest.java fails with OpenJDK: java.lang.RuntimeException: 'java version ' missing from stdout/stderr
hseigel
parents: 40686
diff changeset
    93
            documentMatch(output.getStdout(), ".*Runtime Environment.*Runtime Environment.*");
38956
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    94
        } finally {
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    95
            JInfoTestLingeredApp.stopApp(app1);
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    96
            JInfoTestLingeredApp.stopApp(app2);
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    97
        }
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    98
    }
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
    99
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
   100
    private static void documentMatch(String data, String pattern){
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
   101
        Matcher matcher = Pattern.compile(pattern, Pattern.DOTALL).matcher(data);
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
   102
        if (!matcher.find()) {
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
   103
            throw new RuntimeException("'" + pattern + "' missing from stdout \n");
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
   104
        }
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
   105
    }
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
   106
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
   107
    private static OutputAnalyzer jinfo(String... toolArgs) throws Exception {
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
   108
        JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jinfo");
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
   109
        if (toolArgs != null) {
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
   110
            for (String toolArg : toolArgs) {
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
   111
                launcher.addToolArg(toolArg);
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
   112
            }
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
   113
        }
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
   114
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
   115
        processBuilder.command(launcher.getCommand());
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
   116
        OutputAnalyzer output = ProcessTools.executeProcess(processBuilder);
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
   117
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
   118
        return output;
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
   119
    }
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
   120
}
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
   121
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
   122
// Sometime there is LingeredApp's from other test still around
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
   123
class JInfoTestLingeredApp extends LingeredApp {
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
   124
}
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
diff changeset
   125