1 /* 2 * Copyright (c) 2014, 2015, 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 */ 24 25 package compiler.rtm.cli; 26 27 import jdk.test.lib.ExitCode; 28 import jdk.test.lib.Platform; 29 import jdk.test.lib.cli.CommandLineOptionTest; 30 31 import java.util.function.BooleanSupplier; 32 33 public abstract class TestPrintPreciseRTMLockingStatisticsBase 34 extends RTMGenericCommandLineOptionTest { 35 protected static final String DEFAULT_VALUE = "false"; 36 37 protected TestPrintPreciseRTMLockingStatisticsBase( 38 BooleanSupplier predicate) { 39 super(predicate, "PrintPreciseRTMLockingStatistics", true, false, 40 TestPrintPreciseRTMLockingStatisticsBase.DEFAULT_VALUE); 41 } 42 43 @Override 44 protected void runNonX86TestCases() throws Throwable { 45 verifyJVMStartup(); 46 verifyOptionValues(); 47 } 48 49 @Override 50 protected void verifyJVMStartup() throws Throwable { 51 if (Platform.isServer()) { 52 if (!Platform.isDebugBuild()) { 53 String shouldFailMessage = String.format("VM option '%s' is " 54 + "diagnostic%nJVM startup should fail without " 55 + "-XX:\\+UnlockDiagnosticVMOptions flag", optionName); 56 String shouldPassMessage = String.format("VM option '%s' is " 57 + "diagnostic%nJVM startup should pass with " 58 + "-XX:\\+UnlockDiagnosticVMOptions in debug build", 59 optionName); 60 String errorMessage = CommandLineOptionTest. 61 getDiagnosticOptionErrorMessage(optionName); 62 // verify that option is actually diagnostic 63 CommandLineOptionTest.verifySameJVMStartup( 64 new String[] { errorMessage }, null, shouldFailMessage, 65 shouldFailMessage, ExitCode.FAIL, 66 prepareOptionValue("true")); 67 68 CommandLineOptionTest.verifySameJVMStartup(null, 69 new String[] { errorMessage }, shouldPassMessage, 70 shouldPassMessage + "without any warnings", ExitCode.OK, 71 CommandLineOptionTest.UNLOCK_DIAGNOSTIC_VM_OPTIONS, 72 prepareOptionValue("true")); 73 } else { 74 String shouldPassMessage = String.format("JVM startup should " 75 + "pass with '%s' option in debug build", 76 optionName); 77 CommandLineOptionTest.verifySameJVMStartup(null, null, 78 shouldPassMessage, shouldPassMessage, 79 ExitCode.OK, prepareOptionValue("true")); 80 } 81 } else { 82 String errorMessage = CommandLineOptionTest. 83 getUnrecognizedOptionErrorMessage(optionName); 84 String shouldFailMessage = String.format("JVM startup should fail" 85 + " with '%s' option in not debug build", optionName); 86 CommandLineOptionTest.verifySameJVMStartup( 87 new String[]{errorMessage}, null, shouldFailMessage, 88 shouldFailMessage, ExitCode.FAIL, 89 CommandLineOptionTest.UNLOCK_DIAGNOSTIC_VM_OPTIONS, 90 prepareOptionValue("true")); 91 } 92 } 93 94 @Override 95 protected void verifyOptionValues() throws Throwable { 96 if (Platform.isServer()) { 97 // Verify default value 98 CommandLineOptionTest.verifyOptionValueForSameVM(optionName, 99 TestPrintPreciseRTMLockingStatisticsBase.DEFAULT_VALUE, 100 String.format("Option '%s' should have '%s' default value", 101 optionName, 102 TestPrintPreciseRTMLockingStatisticsBase.DEFAULT_VALUE), 103 CommandLineOptionTest.UNLOCK_DIAGNOSTIC_VM_OPTIONS); 104 } 105 } 106 }