Path: blob/master/test/jdk/tools/launcher/Settings.java
41144 views
/*1* Copyright (c) 2010, 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22import java.io.File;23import java.io.IOException;2425/*26* @test27* @bug 6994753 712358228* @summary tests -XshowSettings options29* @modules jdk.compiler30* jdk.zipfs31* @compile -XDignore.symbol.file Settings.java32* @run main Settings33* @author ksrini34*/35public class Settings extends TestHelper {36private static File testJar = null;3738static void init() throws IOException {39if (testJar != null) {40return;41}42testJar = new File("test.jar");43StringBuilder tsrc = new StringBuilder();44tsrc.append("public static void main(String... args) {\n");45tsrc.append(" for (String x : args) {\n");46tsrc.append(" System.out.println(x);\n");47tsrc.append(" }\n");48tsrc.append("}\n");49createJar(testJar, tsrc.toString());50}5152static void checkContains(TestResult tr, String str) {53if (!tr.contains(str)) {54System.out.println(tr);55throw new RuntimeException(str + " not found");56}57}5859static void checkNotContains(TestResult tr, String str) {60if (!tr.notContains(str)) {61System.out.println(tr);62throw new RuntimeException(str + " found");63}64}6566private static final String VM_SETTINGS = "VM settings:";67private static final String PROP_SETTINGS = "Property settings:";68private static final String LOCALE_SETTINGS = "Locale settings:";69private static final String SYSTEM_SETTINGS = "Operating System Metrics:";70private static final String STACKSIZE_SETTINGS = "Stack Size:";7172static void containsAllOptions(TestResult tr) {73checkContains(tr, VM_SETTINGS);74checkContains(tr, PROP_SETTINGS);75checkContains(tr, LOCALE_SETTINGS);76if (System.getProperty("os.name").contains("Linux")) {77checkContains(tr, SYSTEM_SETTINGS);78}79}8081static void runTestOptionDefault() throws IOException {82int stackSize = 256; // in kb83if (getArch().equals("ppc64") || getArch().equals("ppc64le")) {84stackSize = 800;85} else if (getArch().equals("aarch64")) {86/*87* The max value of minimum stack size allowed for aarch64 can be estimated as88* such: suppose the vm page size is 64KB and the test runs with a debug build,89* the initial _java_thread_min_stack_allowed defined in os_linux_aarch64.cpp is90* 72K, stack guard zones could take 192KB, and the shadow zone needs 128KB,91* after aligning up all parts to the page size, the final size would be 448KB.92* See details in JDK-816336393*/94stackSize = 448;95}96TestResult tr;97tr = doExec(javaCmd, "-Xms64m", "-Xmx512m",98"-Xss" + stackSize + "k", "-XshowSettings", "-jar", testJar.getAbsolutePath());99// Check the stack size logs printed by -XshowSettings to verify -Xss meaningfully.100checkContains(tr, STACKSIZE_SETTINGS);101containsAllOptions(tr);102if (!tr.isOK()) {103System.out.println(tr);104throw new RuntimeException("test fails");105}106tr = doExec(javaCmd, "-Xms65536k", "-Xmx712m",107"-Xss" + (stackSize * 1024), "-XshowSettings", "-jar", testJar.getAbsolutePath());108checkContains(tr, STACKSIZE_SETTINGS);109containsAllOptions(tr);110if (!tr.isOK()) {111System.out.println(tr);112throw new RuntimeException("test fails");113}114}115116static void runTestOptionAll() throws IOException {117init();118TestResult tr = doExec(javaCmd, "-XshowSettings:all");119containsAllOptions(tr);120}121122static void runTestOptionVM() throws IOException {123TestResult tr = doExec(javaCmd, "-XshowSettings:vm");124checkContains(tr, VM_SETTINGS);125checkNotContains(tr, PROP_SETTINGS);126checkNotContains(tr, LOCALE_SETTINGS);127}128129static void runTestOptionProperty() throws IOException {130TestResult tr = doExec(javaCmd, "-XshowSettings:properties");131checkNotContains(tr, VM_SETTINGS);132checkContains(tr, PROP_SETTINGS);133checkNotContains(tr, LOCALE_SETTINGS);134}135136static void runTestOptionLocale() throws IOException {137TestResult tr = doExec(javaCmd, "-XshowSettings:locale");138checkNotContains(tr, VM_SETTINGS);139checkNotContains(tr, PROP_SETTINGS);140checkContains(tr, LOCALE_SETTINGS);141}142143static void runTestOptionSystem() throws IOException {144TestResult tr = doExec(javaCmd, "-XshowSettings:system");145if (System.getProperty("os.name").contains("Linux")) {146checkNotContains(tr, VM_SETTINGS);147checkNotContains(tr, PROP_SETTINGS);148checkNotContains(tr, LOCALE_SETTINGS);149checkContains(tr, SYSTEM_SETTINGS);150} else {151// -XshowSettings prints all available settings when152// settings argument is not recognized.153containsAllOptions(tr);154}155}156157static void runTestBadOptions() throws IOException {158TestResult tr = doExec(javaCmd, "-XshowSettingsBadOption");159checkNotContains(tr, VM_SETTINGS);160checkNotContains(tr, PROP_SETTINGS);161checkNotContains(tr, LOCALE_SETTINGS);162checkContains(tr, "Unrecognized option: -XshowSettingsBadOption");163}164165static void runTest7123582() throws IOException {166TestResult tr = doExec(javaCmd, "-XshowSettings", "-version");167if (!tr.isOK()) {168System.out.println(tr);169throw new RuntimeException("test fails");170}171containsAllOptions(tr);172}173174public static void main(String... args) throws IOException {175runTestOptionAll();176runTestOptionDefault();177runTestOptionVM();178runTestOptionProperty();179runTestOptionLocale();180runTestOptionSystem();181runTestBadOptions();182runTest7123582();183if (testExitValue != 0) {184throw new Error(testExitValue + " tests failed");185}186}187}188189190