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