jdk/test/tools/launcher/Settings.java
author mchung
Tue, 29 Mar 2011 15:50:55 -0700
changeset 9013 eedac0b9f552
parent 7810 d4730191e53c
child 11363 09b0c9731145
permissions -rw-r--r--
7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management Reviewed-by: alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7297
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
     1
/*
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
     2
 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
     4
 *
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
     7
 * published by the Free Software Foundation.
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
     8
 *
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    13
 * accompanied this code).
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    14
 *
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    18
 *
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    21
 * questions.
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    22
 */
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    23
import java.io.File;
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    24
import java.io.IOException;
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    25
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    26
/*
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    27
 * @test
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    28
 * @bug 6994753
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    29
 * @summary tests -XshowSettings options
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    30
 * @compile -XDignore.symbol.file Settings.java TestHelper.java
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    31
 * @run main Settings
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    32
 * @author ksrini
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    33
 */
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    34
public class Settings {
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    35
    private static File testJar = null;
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    36
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    37
    static void init() throws IOException {
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    38
        if  (testJar != null) {
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    39
            return;
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    40
        }
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    41
        testJar = new File("test.jar");
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    42
        StringBuilder tsrc = new StringBuilder();
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    43
        tsrc.append("public static void main(String... args) {\n");
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    44
        tsrc.append("   for (String x : args) {\n");
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    45
        tsrc.append("        System.out.println(x);\n");
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    46
        tsrc.append("   }\n");
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    47
        tsrc.append("}\n");
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    48
        TestHelper.createJar(testJar, tsrc.toString());
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    49
    }
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    50
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    51
    static void checkContains(TestHelper.TestResult tr, String str) {
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    52
        if (!tr.contains(str)) {
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    53
            System.out.println(tr);
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    54
            throw new RuntimeException(str + " not found");
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    55
        }
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    56
    }
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    57
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    58
    static void checkNoContains(TestHelper.TestResult tr, String str) {
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    59
        if (tr.contains(str)) {
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    60
            System.out.println(tr.status);
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    61
            throw new RuntimeException(str + " found");
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    62
        }
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    63
    }
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    64
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    65
    private static final String VM_SETTINGS = "VM settings:";
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    66
    private static final String PROP_SETTINGS = "Property settings:";
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    67
    private static final String LOCALE_SETTINGS = "Locale settings:";
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    68
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    69
    static void containsAllOptions(TestHelper.TestResult tr) {
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    70
        checkContains(tr, VM_SETTINGS);
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    71
        checkContains(tr, PROP_SETTINGS);
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    72
        checkContains(tr, LOCALE_SETTINGS);
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    73
    }
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    74
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    75
    static void runTestOptionDefault() throws IOException {
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    76
        TestHelper.TestResult tr = null;
7810
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
    77
        tr = TestHelper.doExec(TestHelper.javaCmd, "-Xms64m", "-Xmx512m",
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
    78
                "-Xss128k", "-XshowSettings", "-jar", testJar.getAbsolutePath());
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
    79
        containsAllOptions(tr);
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
    80
        if (!tr.isOK()) {
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
    81
            System.out.println(tr.status);
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
    82
            throw new RuntimeException("test fails");
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
    83
        }
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
    84
        tr = TestHelper.doExec(TestHelper.javaCmd, "-Xms65536k", "-Xmx712m",
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
    85
                "-Xss122880", "-XshowSettings", "-jar", testJar.getAbsolutePath());
7297
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    86
        containsAllOptions(tr);
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    87
        if (!tr.isOK()) {
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    88
            System.out.println(tr.status);
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    89
            throw new RuntimeException("test fails");
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    90
        }
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    91
    }
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    92
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    93
    static void runTestOptionAll() throws IOException {
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    94
        init();
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    95
        TestHelper.TestResult tr = null;
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    96
        tr = TestHelper.doExec(TestHelper.javaCmd, "-XshowSettings:all");
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    97
        containsAllOptions(tr);
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    98
    }
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
    99
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
   100
    static void runTestOptionVM() throws IOException {
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
   101
        TestHelper.TestResult tr = null;
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
   102
        tr = TestHelper.doExec(TestHelper.javaCmd, "-XshowSettings:vm");
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
   103
        checkContains(tr, VM_SETTINGS);
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
   104
        checkNoContains(tr, PROP_SETTINGS);
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
   105
        checkNoContains(tr, LOCALE_SETTINGS);
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
   106
    }
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
   107
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
   108
    static void runTestOptionProperty() throws IOException {
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
   109
        TestHelper.TestResult tr = null;
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
   110
        tr = TestHelper.doExec(TestHelper.javaCmd, "-XshowSettings:properties");
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
   111
        checkNoContains(tr, VM_SETTINGS);
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
   112
        checkContains(tr, PROP_SETTINGS);
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
   113
        checkNoContains(tr, LOCALE_SETTINGS);
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
   114
    }
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
   115
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
   116
    static void runTestOptionLocale() throws IOException {
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
   117
        TestHelper.TestResult tr = null;
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
   118
        tr = TestHelper.doExec(TestHelper.javaCmd, "-XshowSettings:locale");
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
   119
        checkNoContains(tr, VM_SETTINGS);
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
   120
        checkNoContains(tr, PROP_SETTINGS);
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
   121
        checkContains(tr, LOCALE_SETTINGS);
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
   122
    }
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
   123
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
   124
    static void runTestBadOptions() throws IOException {
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
   125
        TestHelper.TestResult tr = null;
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
   126
        tr = TestHelper.doExec(TestHelper.javaCmd, "-XshowSettingsBadOption");
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
   127
        checkNoContains(tr, VM_SETTINGS);
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
   128
        checkNoContains(tr, PROP_SETTINGS);
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
   129
        checkNoContains(tr, LOCALE_SETTINGS);
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
   130
        checkContains(tr, "Unrecognized option: -XshowSettingsBadOption");
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
   131
    }
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
   132
    public static void main(String... args) {
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
   133
        try {
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
   134
            runTestOptionAll();
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
   135
            runTestOptionDefault();
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
   136
            runTestOptionVM();
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
   137
            runTestOptionProperty();
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
   138
            runTestOptionLocale();
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
   139
            runTestBadOptions();
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
   140
        } catch (IOException ioe) {
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
   141
            throw new RuntimeException(ioe);
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
   142
        }
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
   143
    }
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents:
diff changeset
   144
}