1 /* 2 * Copyright (c) 2010, 2017, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 import java.io.File; 24 import java.io.IOException; 25 26 /* 27 * @test 28 * @bug 6994753 7123582 29 * @summary tests -XshowSettings options 30 * @modules jdk.compiler 31 * jdk.zipfs 32 * @compile -XDignore.symbol.file Settings.java 33 * @run main Settings 34 * @author ksrini 35 */ 36 public class Settings extends TestHelper { 37 private static File testJar = null; 38 39 static void init() throws IOException { 40 if (testJar != null) { 41 return; 42 } 43 testJar = new File("test.jar"); 44 StringBuilder tsrc = new StringBuilder(); 45 tsrc.append("public static void main(String... args) {\n"); 46 tsrc.append(" for (String x : args) {\n"); 47 tsrc.append(" System.out.println(x);\n"); 48 tsrc.append(" }\n"); 49 tsrc.append("}\n"); 50 createJar(testJar, tsrc.toString()); 51 } 52 53 static void checkContains(TestResult tr, String str) { 54 if (!tr.contains(str)) { 55 System.out.println(tr); 56 throw new RuntimeException(str + " not found"); 57 } 58 } 59 60 static void checkNotContains(TestResult tr, String str) { 61 if (!tr.notContains(str)) { 62 System.out.println(tr); 63 throw new RuntimeException(str + " found"); 64 } 65 } 66 67 private static final String VM_SETTINGS = "VM settings:"; 68 private static final String PROP_SETTINGS = "Property settings:"; 69 private static final String LOCALE_SETTINGS = "Locale settings:"; 70 71 static void containsAllOptions(TestResult tr) { 72 checkContains(tr, VM_SETTINGS); 73 checkContains(tr, PROP_SETTINGS); 74 checkContains(tr, LOCALE_SETTINGS); 75 } 76 77 static void runTestOptionDefault() throws IOException { 78 int stackSize = 256; // in kb 79 if (getArch().equals("ppc64") || getArch().equals("ppc64le")) { 80 stackSize = 800; 81 } 82 TestResult tr; 83 tr = doExec(javaCmd, "-Xms64m", "-Xmx512m", 84 "-Xss" + stackSize + "k", "-XshowSettings", "-jar", testJar.getAbsolutePath()); 85 containsAllOptions(tr); 86 if (!tr.isOK()) { 87 System.out.println(tr); 88 throw new RuntimeException("test fails"); 89 } 90 tr = doExec(javaCmd, "-Xms65536k", "-Xmx712m", 91 "-Xss" + (stackSize * 1024), "-XshowSettings", "-jar", testJar.getAbsolutePath()); 92 containsAllOptions(tr); 93 if (!tr.isOK()) { 94 System.out.println(tr); 95 throw new RuntimeException("test fails"); 96 } 97 } 98 99 static void runTestOptionAll() throws IOException { 100 init(); 101 TestResult tr = doExec(javaCmd, "-XshowSettings:all"); 102 containsAllOptions(tr); 103 } 104 105 static void runTestOptionVM() throws IOException { 106 TestResult tr = doExec(javaCmd, "-XshowSettings:vm"); 107 checkContains(tr, VM_SETTINGS); 108 checkNotContains(tr, PROP_SETTINGS); 109 checkNotContains(tr, LOCALE_SETTINGS); 110 } 111 112 static void runTestOptionProperty() throws IOException { 113 TestResult tr = doExec(javaCmd, "-XshowSettings:properties"); 114 checkNotContains(tr, VM_SETTINGS); 115 checkContains(tr, PROP_SETTINGS); 116 checkNotContains(tr, LOCALE_SETTINGS); 117 } 118 119 static void runTestOptionLocale() throws IOException { 120 TestResult tr = doExec(javaCmd, "-XshowSettings:locale"); 121 checkNotContains(tr, VM_SETTINGS); 122 checkNotContains(tr, PROP_SETTINGS); 123 checkContains(tr, LOCALE_SETTINGS); 124 } 125 126 static void runTestBadOptions() throws IOException { 127 TestResult tr = doExec(javaCmd, "-XshowSettingsBadOption"); 128 checkNotContains(tr, VM_SETTINGS); 129 checkNotContains(tr, PROP_SETTINGS); 130 checkNotContains(tr, LOCALE_SETTINGS); 131 checkContains(tr, "Unrecognized option: -XshowSettingsBadOption"); 132 } 133 134 static void runTest7123582() throws IOException { 135 TestResult tr = doExec(javaCmd, "-XshowSettings", "-version"); 136 if (!tr.isOK()) { 137 System.out.println(tr); 138 throw new RuntimeException("test fails"); 139 } 140 containsAllOptions(tr); 141 } 142 143 public static void main(String... args) throws IOException { 144 runTestOptionAll(); 145 runTestOptionDefault(); 146 runTestOptionVM(); 147 runTestOptionProperty(); 148 runTestOptionLocale(); 149 runTestBadOptions(); 150 runTest7123582(); 151 if (testExitValue != 0) { 152 throw new Error(testExitValue + " tests failed"); 153 } 154 } 155 }